#include <bits/stdc++.h>
using namespace std;
char str[100005];
int flag[100005];
void print(int len) {
  for (int i = 0; i < len / 2; i++) {
    printf("4");
  }
  for (int j = len / 2; j < len; j++) {
    printf("7");
  }
  printf("\n");
}
int main() {
  while (~scanf("%s", str)) {
    int flag1 = 0;
    int len = strlen(str);
    memset(flag, 0, sizeof(flag));
    if (len % 2) {
      print(len + 1);
      continue;
    }
    if ((str[0] - '0') > 7) {
      print(len + 2);
      continue;
    }
    int cnt = 0, x = 0, y = 0;
    for (int i = len - 1; i >= 0; i--) {
      if ((str[i] - '0' + cnt) > 7) {
        if (i == 0) {
          print(len + 2);
          flag1 = 1;
          break;
        }
        cnt = 1;
        str[i] = '4';
      } else if ((str[i] - '0' + cnt) > 4 && (str[i] - '0' + cnt) < 7) {
        cnt = 0;
        str[i] = '7';
        flag[i + 1] = 1;
      } else if ((str[i] - '0' + cnt) < 4) {
        cnt = 0;
        str[i] = '4';
        flag[i + 1] = 1;
      } else if ((str[i] - '0' + cnt) == 4) {
        str[i] = '4';
        if (cnt) {
          flag[i + 1] = 1;
        }
        cnt = 0;
      } else {
        str[i] = '7';
        if (cnt) {
          flag[i + 1] = 1;
        }
        cnt = 0;
      }
    }
    if (flag1) continue;
    int pos = -1;
    for (int i = 0; i < len; i++) {
      if (flag[i]) {
        pos = i;
        break;
      }
    }
    if (pos != -1)
      for (int i = pos; i < len; i++) {
        str[i] = '4';
      }
    for (int i = 0; i < len; i++) {
      if (str[i] == '4')
        x++;
      else
        y++;
    }
    if (x == y)
      printf("%s\n", str);
    else if (x > y) {
      int ans = x - y;
      for (int i = len - 1; i >= 0; i--) {
        if (ans == 0) {
          printf("%s\n", str);
          break;
        } else {
          if (str[i] == '4') {
            str[i] = '7';
            ans -= 2;
          }
        }
      }
    } else {
      int ans = y - x;
      for (int i = len - 1; i >= 0; i--) {
        int p = 0;
        if ((str[i] - '0') == 4) {
          for (int j = 0; j < i; j++) {
            if (str[j] == '4') p++;
          }
          if (((len - 1 - i) + p) >= len / 2) {
            str[i] = '7';
            ans += 2;
            for (int j = i + 1; j <= len; j++) {
              if (ans == 0) {
                printf("%s\n", str);
                flag1 = 1;
                break;
              }
              if (str[j] == '7') {
                str[j] = '4';
                ans -= 2;
              }
            }
          }
        }
        if (flag1) break;
      }
      if (flag1) continue;
      print(len + 2);
    }
  }
  return 0;
}
