#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int MAXM = 300010;
const int INF = 0x7fffffff;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const long double pi = acos(-1.0);
char ans[100010], st[100010];
void fuck(int i, int j) {
  while (ans[j]) {
    swap(ans[j], ans[i]);
    i++;
    j++;
  }
}
int main() {
  scanf("%s", st);
  int n = strlen(st);
  if (n & 1 == 1) {
    for (int i = 0; i < n / 2 + 1; ++i) {
      printf("4");
    }
    for (int i = 0; i < n / 2 + 1; ++i) {
      printf("7");
    }
    printf("\n");
    return 0;
  }
  int m = n / 2;
  for (int i = 0; i < m; ++i) {
    ans[i] = '7';
  }
  for (int i = 0; i < m; ++i) {
    ans[m + i] = '4';
  }
  bool t = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] > st[i]) break;
    if (ans[i] < st[i]) {
      t = 1;
      break;
    }
  }
  if (t) {
    for (int j = 0; j < n / 2 + 1; ++j) {
      printf("4");
    }
    for (int j = 0; j < n / 2 + 1; ++j) {
      printf("7");
    }
    printf("\n");
    return 0;
  }
  int nxt = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] > st[i]) {
      nxt = i;
      break;
    }
  }
  ans[n] = 0;
  st[n] = -1;
  while (nxt < n) {
    for (int i = nxt; i <= n; ++i) {
      if (ans[i] > st[i]) {
        nxt = i;
        break;
      }
    }
    if (nxt == n || ans[nxt] == '4') break;
    if (st[nxt] < '4') {
      fuck(nxt, m);
      break;
    }
    if (st[nxt] == '4') {
      swap(ans[nxt], ans[m]);
      int i;
      for (i = nxt; i <= n; ++i) {
        if (ans[i] != st[i]) break;
      }
      if (ans[i] > st[i]) {
        m++;
        nxt = i;
        continue;
      }
      swap(ans[nxt], ans[m]);
      fuck(nxt + 1, m);
      break;
    }
    if (st[nxt] < '7') {
      fuck(nxt + 1, m);
      break;
    }
  }
  printf("%s\n", ans);
}
