#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> a;
ll N;
void dfs(ll now, int four, int seven)
{
if (now > 100000000000ll) return;
if (four == seven) {a.push_back(now);}
//cout<<now<<endl;
dfs(now * 10 + 4, four + 1, seven);
dfs(now * 10 + 7, four, seven + 1);
}
int main()
{
cin >> N;
a.clear();
dfs(0, 0, 0);
sort(a.begin(), a.end());
int u = 0;
for (; a[u] < N; ++u);
cout << a[u] << endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZglsb25nIGxvbmcgbGw7CnZlY3RvcjxsbD4JYTsKbGwgTjsKdm9pZAlkZnMobGwgbm93LCBpbnQgZm91ciwgaW50IHNldmVuKQp7CglpZiAobm93ID4gMTAwMDAwMDAwMDAwbGwpIHJldHVybjsKCWlmIChmb3VyID09IHNldmVuKSB7YS5wdXNoX2JhY2sobm93KTt9CiAgICAvL2NvdXQ8PG5vdzw8ZW5kbDsKCWRmcyhub3cgKiAxMCArIDQsIGZvdXIgKyAxLCBzZXZlbik7CglkZnMobm93ICogMTAgKyA3LCBmb3VyLCBzZXZlbiArIDEpOwp9CgppbnQJbWFpbigpCnsKCWNpbiA+PiBOOwoJYS5jbGVhcigpOwoJZGZzKDAsIDAsIDApOwoJc29ydChhLmJlZ2luKCksIGEuZW5kKCkpOwoJaW50IHUgPSAwOwoJZm9yICg7IGFbdV0gPCBOOyArK3UpOwoJY291dCA8PCBhW3VdIDw8IGVuZGw7CgoJcmV0dXJuIDA7Cn0K