#include <iostream>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    for (int i = 1;i <= n; ++i) { // 注意 while 处理多个 case
        if(i % 4 != 0){
            string s = to_string(i);
            if(s.find('4') == string::npos){
                cout << i << endl;
            }
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")