#include <bits/stdc++.h>
using namespace std;
void exceed(int j) {
  int i;
  j = j / 2;
  for (i = 0; i < j; i++) cout << 4;
  for (i = 0; i < j; i++) cout << 7;
}
int main() {
  int sta[20];
  int i, j, k, l, four = 0, seven = 0;
  ;
  bool f = true;
  char s[20];
  scanf("%s", s);
  j = strlen(s);
  if (j % 2) {
    exceed(j + 1);
    return 0;
  }
  i = 0;
  while (f && s[i] != 0) {
    switch (s[i]) {
      case '0':
      case '1':
      case '2':
      case '3':
        f = false;
        sta[i] = 1;
        four++;
        for (k = i + 1; s[k] != 0; k++) {
          if (four < j / 2) {
            sta[k] = 1;
            four++;
          } else {
            sta[k] = 2;
            seven++;
          }
        }
        break;
      case '4':
        sta[i] = 1;
        four++;
        break;
      case '5':
      case '6':
        f = false;
        sta[i] = 2;
        for (k = i + 1; s[k] != 0; k++) {
          if (four < j / 2) {
            sta[k] = 1;
            four++;
          } else {
            sta[k] = 2;
            seven++;
          }
        }
        break;
      case '7':
        if (seven < j / 2) {
          sta[i] = 2;
          seven++;
          break;
        }
      case '8':
      case '9':
        f = false;
        sta[i] = 1;
        if (i == 0) {
          exceed(j + 2);
          return 0;
        }
        k = i - 1;
        while (sta[k] == 2) {
          sta[k] = 1;
          k--;
          if (k < 0) {
            exceed(j + 2);
            return 0;
          }
        }
        sta[k] = 2;
        four = 0;
        seven = 0;
        for (l = 0; l <= k; l++) {
          if (sta[l] == 1)
            four++;
          else {
            seven++;
            if (seven > j / 2) {
              exceed(j + 2);
              return 0;
            }
          }
        }
        for (; s[l] != 0; l++) {
          if (four < j / 2) {
            sta[l] = 1;
            four++;
          } else {
            sta[l] = 2;
            seven++;
          }
        }
    }
    i++;
  }
  i = 0;
  while (s[i] != 0) {
    switch (sta[i]) {
      case 1:
        cout << 4;
        break;
      case 2:
        cout << 7;
        break;
    }
    i++;
  }
  return 0;
}
