#include <bits/stdc++.h>
using namespace std;
string s;
bool ch(string t) {
  if (t.size() > s.size()) return true;
  int i = 0;
  while (i < s.size() && s[i] == t[i]) i++;
  if (i == s.size() || t[i] > s[i]) return true;
  return false;
}
int main() {
  string t;
  cin >> s;
  int n = s.size();
  if (n % 2 != 0) n++;
  for (int i = 0; i < n / 2; i++) t += "4";
  for (int i = 0; i < n / 2; i++) t += "7";
  string e = t;
  do {
    if (ch(t)) {
      cout << t << endl;
      return 0;
    }
  } while (next_permutation(t.begin(), t.end()));
  cout << 4 << e << 7 << endl;
}
