#include<cstdio>
#include<iostream>
using namespace std;
#define b(i) (i*i)
int judge(int x){
while(x){
int t=x%10;
if(t==3||t==5) return 0;
x/=10;
}
return 1;
}
int main(){
int n,sum=5;
scanf("%d",&n);
for(int i=3;i<=n;i++){
if(i%3!=0&&i%5!=0&&judge(i)){
sum+=b(i);
}
}
printf("%d\n",sum);
return 0;
}