#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
char txt[N];
int czworki[N], siodemki[N];
int main() {
  scanf("%s", txt);
  int n = strlen(txt);
  if (n % 2 == 1) {
    for (int i = (n - 1); i >= (0); --i) txt[i + 1] = txt[i];
    txt[0] = '0';
    n++;
    txt[n] = 0;
  }
  int a = 0, b = 0;
  for (int i = 0; i < (n); ++i) {
    czworki[i] = a;
    siodemki[i] = b;
    if (txt[i] == '4') a++;
    if (txt[i] == '7') b++;
  }
  if (a + b == n && a == b) {
    puts(txt);
    return 0;
  }
  for (int i = (n - 1); i >= (0); --i) {
    a = czworki[i];
    b = siodemki[i];
    if (a + b != i || a > n / 2 || b > n / 2) continue;
    int co = -1;
    if (txt[i] < '4' && (a + 1) <= n / 2)
      co = 4;
    else if (txt[i] < '7' && (b + 1) <= n / 2)
      co = 7;
    if (co == -1) continue;
    for (int j = 0; j < (i); ++j) putchar(txt[j]);
    putchar('0' + co);
    if (co == 4)
      a++;
    else
      b++;
    for (int j = 0; j < (n - (i + 1)); ++j) {
      if (a + 1 <= n / 2)
        putchar('4'), a++;
      else
        putchar('7');
    }
    puts("");
    return 0;
  }
  for (int i = 0; i < (n / 2 + 1); ++i) putchar('4');
  for (int i = 0; i < (n / 2 + 1); ++i) putchar('7');
  puts("");
  return 0;
}
