#include <iostream>
using namespace std;

int main() {
    int n;
    while (cin >> n) { // 注意 while 处理多个 case
        for (int i=1; i<=n; i++) {
            if (i%4!=0) {
                int tempi=i;
                bool flag = false;
                while (tempi>0) {
                    if(tempi%10==4){
                        flag = true;
                        break;
                    }
                    tempi = tempi/10;
                }
                if (flag==false) {cout<<i<<endl;}
            }
        }
    }
}
// 64 位输出请用 printf("%lld")