#include <bits/stdc++.h>
using namespace std;
long long int x, x2 = 1, e = 0, ans = 100000000000;
void mnum(int i, long long int t, int x4, int x7) {
  if (i == e) {
    if (t < ans && t >= x && x4 == x7) ans = t;
    return;
  }
  long long int v = 1;
  for (int z = 1; z <= i; z++) v *= 10;
  mnum(i + 1, t + (v * 4), x4 + 1, x7);
  mnum(i + 1, t + (v * 7), x4, x7 + 1);
}
int main() {
  cin >> x;
  x2 = x;
  while (x2) {
    x2 /= 10;
    e++;
  }
  while (ans == 100000000000) {
    mnum(0, 0, 0, 0);
    e++;
  }
  cout << ans;
  return 0;
}
