#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int n, a[500], k = 0, k1, b[500];
bool check() {
  for (int i = 0; i < k1; ++i) {
    if (b[i] < a[k1 - i - 1]) return 0;
    if (b[i] > a[k1 - i - 1]) return 1;
  }
  return 1;
}
int main() {
  cin >> n;
  while (n) a[k++] = n % 10, n /= 10;
  k1 = k;
  if (k1 & 1) ++k1;
  for (int i = 0; i < k1 / 2; ++i) b[i] = 4;
  for (int i = k1 / 2; i < k1; ++i) b[i] = 7;
  while (1) {
    do {
      if (check()) {
        for (int i = 0; i < k1; ++i) cout << b[i];
        return 0;
      }
    } while (next_permutation(b, b + k1));
    b[k1 / 2] = 4;
    b[k1] = b[k1 + 1] = 7;
    k1 += 2;
  }
  return 0;
}
