#include <bits/stdc++.h>
using namespace std;
char s[100005];
int n;
int main() {
  while (~scanf("%s", s)) {
    n = strlen(s);
    if (n & 1) {
      n = (n + 1) / 2;
      for (int i = 0; i < n; i++) putchar('4');
      for (int i = 0; i < n; i++) putchar('7');
      puts("");
      continue;
    }
    int c4 = 0, c7 = 0, big = 0, can = 1;
    for (int i = 0; i < n; i++) {
      if (big) {
        while (i < n) {
          c4++;
          s[i] = '4';
          i++;
        }
        break;
      }
      if (s[i] < '4') {
        s[i] = '4';
        c4++;
        big = 1;
      } else if (s[i] == '4')
        c4++;
      else if (s[i] < '7') {
        s[i] = '7';
        c7++;
        big = 1;
      } else if (s[i] == '7')
        c7++;
      else if (s[i] > '7') {
        if (c7 == i) {
          can = 0;
          break;
        }
        int j = i - 1;
        while (s[j] == '7') {
          c7--;
          j--;
        }
        s[j] = '7';
        c4--;
        c7++;
        j++;
        big = 1;
        while (j < n) {
          c4++;
          s[j] = '4';
          j++;
        }
        break;
      }
    }
    if (!can || c4 == 0) {
      n = (n + 2) / 2;
      for (int i = 0; i < n; i++) putchar('4');
      for (int i = 0; i < n; i++) putchar('7');
      puts("");
      continue;
    }
    if (c7 > c4) {
      c7++;
      c4--;
      int j = n - 1;
      for (; j >= 0; j--) {
        if (c7 == c4) break;
        if (s[j] == '7') {
          c7--;
          c4++;
          s[j] = '4';
        }
        s[j] = '4';
      }
      if (j < 0)
        can = 0;
      else {
        while (j >= 0 && s[j] == '7') --j;
        if (j < 0)
          can = 0;
        else {
          s[j] = '7';
          sort(s + j + 1, s + n);
        }
      }
    }
    if (!can) {
      n = (n + 2) / 2;
      for (int i = 0; i < n; i++) putchar('4');
      for (int i = 0; i < n; i++) putchar('7');
      puts("");
      continue;
    }
    int dt = (c4 - c7) / 2;
    for (int i = n - 1; i >= 0; i--) {
      if (dt == 0) break;
      if (s[i] == '4') {
        s[i] = '7';
        dt--;
      }
    }
    puts(s);
  }
}
