#include <bits/stdc++.h>
using namespace std;
char str1[1000000];
char ans[1000000];
int n;
bool chek() {
  int c1, c2;
  c1 = 0;
  c2 = 0;
  for (int i = 0; i < n; i++) {
    if (str1[i] == '4')
      c1++;
    else if (str1[i] == '7')
      c2++;
    else
      return false;
  }
  return (c1 == c2);
}
bool banano(int pos, int c1, int c2, int l) {
  if (pos == n) {
    if (c1 == c2 && c1 == 0 && l == 1) return true;
    return false;
  }
  if (l == 1) {
    int i = pos;
    while (c1--) ans[i] = '4', i++;
    while (c2--) ans[i] = '7', i++;
    ans[i] = 0;
    return true;
  }
  if (str1[pos] < '4') {
    if (c1 > 0) {
      ans[pos] = '4';
      if (banano(pos + 1, c1 - 1, c2, 1)) return true;
      return false;
    }
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 1)) return true;
      return false;
    }
  } else if (str1[pos] == '4') {
    if (c1 > 0) {
      ans[pos] = '4';
      if (banano(pos + 1, c1 - 1, c2, 0)) return true;
    }
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 1)) return true;
      return false;
    }
  } else if (str1[pos] < '7') {
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 1)) return true;
      return false;
    }
    return false;
  } else if (str1[pos] == '7') {
    if (c2 > 0) {
      ans[pos] = '7';
      if (banano(pos + 1, c1, c2 - 1, 0)) return true;
      return false;
    }
  }
  return false;
}
int main() {
  scanf("%s", &str1);
  n = strlen(str1);
  if (n % 2 == 1) {
    for (int i = 1; i <= (n + 1) / 2; i++) printf("4");
    for (int i = 1; i <= (n + 1) / 2; i++) printf("7");
    printf("\n");
    return 0;
  }
  if (chek()) {
    printf("%s\n", str1);
    return 0;
  }
  if (banano(0, n / 2, n / 2, 0)) {
    printf("%s\n", ans);
    return 0;
  }
  for (int i = 1; i <= (n / 2) + 1; i++) printf("4");
  for (int i = 1; i <= (n / 2) + 1; i++) printf("7");
  printf("\n");
  return 0;
}
