#include<stdio.h>
int main(agrc *agrv)
{
int n,i;
int sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
if(i%3==0&&i%7!=0){
sum+=i;
}
}
printf("%d\n",sum);
}
int main(agrc *agrv)
{
int n,i;
int sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
if(i%3==0&&i%7!=0){
sum+=i;
}
}
printf("%d\n",sum);
}