#include <bits/stdc++.h>
using namespace std;
char num[100010];
int cnt[100010], four[100010], seven[100010];
int main() {
  scanf("%s", num + 1);
  int len = strlen(num + 1), dl = len;
  if (dl & 1)
    dl++;
  else {
    for (int i = 1; i <= dl; i++) {
      int digit = (i <= dl / 2 ? 7 : 4);
      if (digit < num[i] - '0') {
        dl += 2;
        break;
      } else if (digit > num[i] - '0') {
        break;
      }
    }
  }
  if (dl > len) {
    for (int i = 1; i <= dl; i++) {
      int digit = (i <= dl / 2 ? 4 : 7);
      printf("%d", digit);
    }
  } else {
    int pos = -1, digit;
    for (int i = 1; i <= dl; i++) {
      four[i] = four[i - 1];
      seven[i] = seven[i - 1];
      cnt[i] = cnt[i - 1];
      if (num[i] == '4')
        four[i]++;
      else if (num[i] == '7')
        seven[i]++;
      else
        cnt[i]++;
    }
    if (four[dl] == dl / 2 && four[dl] == seven[dl])
      puts(num + 1);
    else {
      for (int i = dl; i >= 1; i--) {
        if (num[i] < '7' && cnt[i - 1] == 0 && seven[i - 1] + 1 <= dl / 2 &&
            four[i - 1] <= dl / 2) {
          pos = i;
          digit = 7;
        }
        if (num[i] < '4' && cnt[i - 1] == 0 && seven[i - 1] <= dl / 2 &&
            four[i - 1] + 1 <= dl / 2) {
          pos = i;
          digit = 4;
        }
        if (pos != -1) break;
      }
      int a = dl / 2, b = dl / 2;
      for (int i = 1; i <= dl; i++) {
        if (i < pos) {
          putchar(num[i]);
          if (num[i] == '4')
            a--;
          else
            b--;
        } else if (i == pos) {
          printf("%d", digit);
          if (digit == 4)
            a--;
          else
            b--;
        } else {
          if (a > 0)
            printf("4"), a--;
          else
            printf("7"), b--;
        }
      }
      puts("");
    }
  }
  return 0;
}
