#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
long long N;
void dfs(long long now, int four, int seven) {
  if (now > 100000000000ll) return;
  if (four == seven) a.push_back(now);
  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;
}
