include<bits/stdc++.h>
using namespace std; typedef long long ll; vector 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;
}