#include <bits/stdc++.h>
using namespace std;
void printopt(int p) {
  for (int i = p / 2; i; i--) printf("4");
  for (int i = p / 2; i; i--) printf("7");
}
char s[100000 + 2];
char s47[100000 + 2];
int n;
bool fopt(int i, int ddif47) {
  if (abs(ddif47) > n - i) return 0;
  int j = i;
  for (; j < i + (n - i - ddif47) / 2; j++) s47[j] = '4';
  for (; j < n; j++) s47[j] = '7';
  return 1;
}
bool f(int i, int dif47) {
  if (i == n) return dif47 == 0;
  switch (s[i] - '0') {
    case 0:
    case 1:
    case 2:
    case 3:
      if (fopt(i, dif47)) return 1;
      break;
    case 4:
      s47[i] = '4';
      if (f(i + 1, dif47 + 1)) return 1;
      s47[i] = '7';
      if (fopt(i + 1, dif47 - 1)) return 1;
      break;
    case 5:
    case 6:
      s47[i] = '7';
      if (fopt(i + 1, dif47 - 1)) return 1;
      break;
    case 7:
      s47[i] = '7';
      if (f(i + 1, dif47 - 1)) return 1;
      break;
    case 8:
    case 9:
      break;
  }
  return 0;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  if (n % 2)
    printopt(n + 1);
  else if (f(0, 0))
    printf("%s", s47);
  else
    printopt(n + 2);
  printf("\n");
}
