#include <bits/stdc++.h>
using namespace std;
string n, s;
long long ok, a, b;
int main() {
  cin >> n;
  if (n.size() & 1) n = string(n.size() + 1, '4');
  for (int i = n.size() - 1; i >= 0; i--) {
    if (n[i] < '4') {
      a = s.size() + 1;
      s.clear();
      s = string(a, '4');
      b = 0;
      ok = 0;
    } else if (n[i] == '4') {
      if (ok == 0) {
        s += '4';
        a++;
      } else {
        a = s.size();
        s.clear();
        s = string(a, '4');
        s += '7';
        ok = 0;
        b = 1;
      }
    } else if (n[i] < '7') {
      a = s.size();
      s.clear();
      s = string(a, '4');
      s += '7';
      ok = 0;
      b = 1;
    } else if (n[i] == '7') {
      if (ok == 0) {
        s += '7';
        b++;
      } else {
        a = s.size() + 1;
        s.clear();
        s = string(a, '4');
        ok = 3;
        b = 0;
      }
    } else {
      s += '4';
      a++;
      ok = 3;
    }
  }
  if (ok != 0) {
    s = string(n.size() + 2, '4');
    a = n.size() + 2;
    b = 0;
  }
  if (a < b) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '4') {
        s[i] = '7';
        a--;
        b++;
        for (int j = i - 1; j >= 0; j--) {
          if (s[j] == '7') {
            b--;
            a++;
            s[j] = '4';
          }
        }
      }
      if (a >= b) break;
    }
    if (b > a) {
      a = s.size() + 2;
      s.clear();
      s = string(a, '4');
      b = 0;
    }
  }
  reverse(s.begin(), s.end());
  long long dif = abs(a - b);
  for (int i = s.size() - 1; i >= 0; i--) {
    if (dif == 0) break;
    if (s[i] == '4') s[i] = '7', dif -= 2;
  }
  cout << s;
}
