#include <bits/stdc++.h>
using namespace std;
char s[100005];
int sum[100005], a[100005], b[100005];
int big, n, seven, four, i;
void Print(int n) {
  if (n & 1) ++n;
  for (int i = 1; i <= n / 2; i++) putchar('4');
  for (int i = 1; i <= n / 2; i++) putchar('7');
  exit(0);
}
void Write() {
  for (int i = 1; i <= n; i++) printf("%d", b[i]);
  exit(0);
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  if (n & 1) Print(n);
  for (i = 1; i <= n; i++) a[i] = s[i] - '0';
  for (i = 1; i <= n; i++)
    if (a[i] != 7) break;
  if (i <= n && a[i] > 7) Print(++n);
  for (i = 1; i <= n; i++)
    if (!big) {
      if (a[i] <= 4)
        b[i] = 4, big = (a[i] < 4);
      else if (a[i] <= 7)
        b[i] = 7, big = (a[i] < 7);
      else {
        for (--i; b[i] != 4; i--)
          ;
        b[i] = 7;
        for (++i; i <= n; i++) b[i] = 4;
        break;
      }
    } else
      b[i] = 4;
  for (i = 1; i <= n; i++) four += b[i] == 4, seven += b[i] == 7;
  if (four == seven) Write();
  if (four > seven) {
    for (i = n; i && four != seven; i--)
      if (b[i] == 4) b[i] = 7, four--, seven++;
    Write();
  }
  for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + (b[i] == 4);
  for (i = n; i; i--)
    if (b[i] == 4 && sum[i - 1] + (n - i) >= n / 2) {
      b[i] = 7;
      seven++;
      four--;
      for (++i; i <= n && seven != four; i++)
        if (b[i] == 7) b[i] = 4, seven--, four++;
      Write();
    }
  Print(n + 1);
}
