#include<bits/stdc++.h>
using namespace std;

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

int main(){
	int n;
	cin>>n;
	
	for(int i=1;i<=n;i++){
		if(del_4(i)){
			cout<<i<<endl;
		}
	}
    return 0;
}