#include <bits/stdc++.h>
using namespace std;
char s[1010000];
int main() {
  int i, j, k, m, n;
  scanf("%s", s);
  n = strlen(s);
  if (n % 2 == 1) {
    n = (n + 1) / 2;
    for (i = 1; i <= n; i++) putchar('4');
    for (i = 1; i <= n; i++) putchar('7');
    puts("");
  } else {
    char u = '7';
    int flag = 0;
    for (i = 0; i < n; i++) {
      if (i + i == n) u = '4';
      if (s[i] > u) {
        flag = -1;
        break;
      } else if (s[i] < u) {
        flag = 1;
        break;
      }
    }
    if (flag == -1) {
      n = (n + 2) / 2;
      for (i = 1; i <= n; i++) putchar('4');
      for (i = 1; i <= n; i++) putchar('7');
      puts("");
    } else {
      int pos = -1;
      int c4 = 0, c7 = 0;
      int f = 0;
      for (i = 0; i < n; i++) {
        if (f || s[i] <= '4') {
          if (s[i] < '4') f = 1;
          s[i] = '4';
          pos = i;
          c4++;
        } else if (s[i] <= '7') {
          if (s[i] < '7') f = 1;
          s[i] = '7';
          c7++;
        } else {
          s[i] = '4';
          s[pos] = '7';
          pos = i;
          c7++;
          f = 1;
        }
      }
      if (c7 > c4) {
        int cnt = 0;
        for (i = n - 1; i >= 0; i--) {
          if (s[i] == '7') cnt++;
          if (cnt >= (c7 - c4) / 2 + 1) break;
        }
        for (; i >= 0; i--)
          if (s[i] == '4') {
            c7++;
            c4--;
            s[i] = '7';
            break;
          }
        for (i = i + 1; i < n; i++)
          if (s[i] == '7') {
            s[i] = '4';
            c7--;
            c4++;
          }
      }
      if (c7 < c4) {
        for (i = n - 1; i >= 0; i--) {
          if (c4 > c7 && s[i] == '4') {
            s[i] = '7';
            c4--;
            c7++;
          }
        }
      }
      puts(s);
    }
  }
  scanf("%*d");
}
