#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  int n = 11;
  long long res = 1e15;
  for (int mask = 0; mask < (1 << n); mask++) {
    long long num = 0;
    int cnt4 = 0, cnt7 = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (mask & (1 << i)) {
        num = num * 10 + 7;
        cnt7++;
      } else {
        num = num * 10 + 4;
        cnt4++;
      }
      if (cnt4 == cnt7 && num >= x) {
        res = min(res, num);
      }
    }
  }
  cout << res << '\n';
}
