#include <iostream>
using namespace std;

bool withFour(int n) {
    while (n != 0) {
        if (n % 10 == 4) return true;
        n /= 10;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 4 == 0) continue;
        if (withFour(i)) continue;
        cout << i << endl;
    }
}
// 64 位输出请用 printf("%lld")