#include <bits/stdc++.h>
using namespace std;
const int M = 100050;
char s[M], tmp[M];
int pos[M], ct[M], cnt1, cnt2;
int main() {
  scanf("%s", s);
  int len = strlen(s);
  bool flag = 0;
  if (len & 1) {
    for (int i = 0; i < (len + 1) >> 1; i++) printf("4");
    for (int i = 0; i < (len + 1) >> 1; i++) printf("7");
    return 0;
  }
  int i, ll = len >> 1;
  for (i = 0; i < len; i++) {
    if (s[i] <= '4') {
      cnt1++;
      if (cnt1 > ll) {
        tmp[i] = '7';
        cnt1--, cnt2++;
        break;
      } else {
        tmp[i] = '4';
        if (s[i] < '4') break;
        pos[cnt1] = i;
        ct[cnt1] = cnt2;
      }
    } else if (s[i] <= '7') {
      cnt2++;
      if (cnt2 > ll) {
        while (cnt1 && ct[cnt1] >= ll) cnt1--;
        if (cnt1 == 0) {
          flag = 1;
          break;
        }
        tmp[i = pos[cnt1]] = '7';
        cnt2 = ct[cnt1--] + 1;
        break;
      } else {
        tmp[i] = '7';
        if (s[i] < '7') break;
      }
    } else {
      while (cnt1 && ct[cnt1] >= ll) cnt1--;
      if (cnt1 == 0) {
        flag = 1;
        break;
      }
      tmp[i = pos[cnt1]] = '7';
      cnt2 = ct[cnt1--] + 1;
      break;
    }
  }
  if (flag) {
    i = ll + 1;
    while (i--) printf("4");
    i = ll + 1;
    while (i--) printf("7");
  } else {
    if (i == len) i--;
    for (int j = 0; j <= i; j++) printf("%c", tmp[j]);
    i = ll - cnt1;
    while (i--) printf("4");
    i = ll - cnt2;
    while (i--) printf("7");
  }
}
