#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
#include <numeric>
typedef std::vector<std::uint64_t> DType;
std::uint64_t MakeHoge(std::uint64_t N){
std::uint64_t i = 1;
DType D;
while (3 * i < N || 5 * i < N){
if (3 * i < N) D.push_back(3 * i);
if (5 * i < N) D.push_back(5 * i);
i++;
}
std::sort(D.begin(), D.end());
D.erase(std::unique(D.begin(), D.end()), D.end());
i = 1;
while (9*i<N){
auto it = std::lower_bound(D.begin(), D.end(), 9 * i);
if(*it == 9*i) it = D.erase(it);
i++;
}
return std::accumulate(D.begin(), D.end(), 0llu);
}
int main(){
std::uint64_t N;
N = MakeHoge(300000);
std::cout << N << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPG51bWVyaWM+CnR5cGVkZWYgc3RkOjp2ZWN0b3I8c3RkOjp1aW50NjRfdD4gRFR5cGU7CgpzdGQ6OnVpbnQ2NF90IE1ha2VIb2dlKHN0ZDo6dWludDY0X3QgTil7CglzdGQ6OnVpbnQ2NF90IGkgPSAxOwoJRFR5cGUgRDsKCXdoaWxlICgzICogaSA8IE4gfHwgNSAqIGkgPCBOKXsKCgkJaWYgKDMgKiBpIDwgTikgRC5wdXNoX2JhY2soMyAqIGkpOwoJCWlmICg1ICogaSA8IE4pIEQucHVzaF9iYWNrKDUgKiBpKTsKCQlpKys7Cgl9CgoJc3RkOjpzb3J0KEQuYmVnaW4oKSwgRC5lbmQoKSk7CglELmVyYXNlKHN0ZDo6dW5pcXVlKEQuYmVnaW4oKSwgRC5lbmQoKSksIEQuZW5kKCkpOwoJaSA9IDE7CgoJd2hpbGUgKDkqaTxOKXsKCQlhdXRvIGl0ID0gc3RkOjpsb3dlcl9ib3VuZChELmJlZ2luKCksIEQuZW5kKCksIDkgKiBpKTsKCQlpZigqaXQgPT0gOSppKSBpdCA9IEQuZXJhc2UoaXQpOwoJCWkrKzsKCX0KCglyZXR1cm4gc3RkOjphY2N1bXVsYXRlKEQuYmVnaW4oKSwgRC5lbmQoKSwgMGxsdSk7Cn0KCmludCBtYWluKCl7CglzdGQ6OnVpbnQ2NF90IE47CgoJTiA9IE1ha2VIb2dlKDMwMDAwMCk7CglzdGQ6OmNvdXQgPDwgTiA8PCBzdGQ6OmVuZGw7CgoJcmV0dXJuIDA7Cgp9