#include <iostream>
using namespace std;

int main()
{
    int i,j; 
    cin>>i;
    for( j = 1;j<=i;j++)
    {
        int temp = j;
        bool z = true;
        for(;temp>0;)
        {

           int n =  temp%10;
            if(n==4) 
            {
                z = false;
                break;
            }
            temp/=10;
        }
        if(j%4!=0 && z) cout<<j<<endl;
    }
       
}
// 64 位输出请用 printf("%lld")