#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int tt = 1;
  for (long long int t = 1; t <= tt; t++) {
    string s;
    cin >> s;
    long long int n = s.size();
    if (n % 2 == 0) {
      string r = "";
      for (long long int i = 1; i <= n; i++) {
        r += (i <= n / 2) ? '7' : '4';
      }
      if (s > r) {
        reverse(r.begin(), r.end());
        cout << "4" << r << "7";
      } else {
        long long int four = n / 2, seven = n / 2;
        bool flag = 0;
        r = "";
        for (long long int i = 0; i <= n - 1; i++) {
          if (s[i] < '4') {
            break;
          } else if (s[i] == '4') {
            if (four == 0) {
              break;
            }
            r += '4';
            four--;
          } else if (s[i] < '7') {
            if (seven > 0) {
              r += '7';
              seven--;
            } else {
              flag = 1;
            }
            break;
          } else if (s[i] == '7') {
            if (seven == 0) {
              flag = 1;
              break;
            }
            r += '7';
            seven--;
          } else {
            flag = 1;
            break;
          }
        }
        if (flag) {
          long long int i = r.size(), index;
          for (long long int j = i - 1; j >= 0; j--) {
            if (s[j] == '4') {
              if (seven > 0) {
                index = j;
                break;
              }
            } else {
              seven++;
            }
          }
          r = "";
          four = seven = n / 2;
          for (long long int j = 0; j <= index - 1; j++) {
            r += s[j];
            (s[j] == '4') ? four-- : seven--;
          }
          r += '7';
          seven--;
        }
        while (four--) {
          r += '4';
        }
        while (seven--) {
          r += '7';
        }
        cout << r;
      }
    } else {
      for (long long int i = 1; i <= n / 2 + 1; i++) {
        cout << "4";
      }
      for (long long int i = 1; i <= n / 2 + 1; i++) {
        cout << "7";
      }
    }
    cout << '\n';
  }
  return 0;
}
