#include <bits/stdc++.h>
using namespace std;
int n, i, j, c4[100005], c7[100005], co[100005];
char s[1000005];
int main() {
  gets(s);
  n = strlen(s);
  for (i = 0; i < n; i++) {
    if (i > 0) {
      c4[i] = c4[i - 1];
      c7[i] = c7[i - 1];
      co[i] = co[i - 1];
    }
    if (s[i] == '4')
      c4[i]++;
    else if (s[i] == '7')
      c7[i]++;
    else
      co[i]++;
  }
  if (n % 2 == 0 && co[n - 1] == 0 && c4[n - 1] == c7[n - 1]) {
    puts(s);
    exit(0);
  }
  if (n % 2 == 0)
    for (i = n - 1; i >= 0; i--)
      if (i == 0 || co[i - 1] == 0) {
        for (j = (s[i] - '0') + 1; j < 10; j++)
          if (j == 4 || j == 7) {
            int n4 = (i == 0) ? 0 : c4[i - 1];
            int n7 = (i == 0) ? 0 : c7[i - 1];
            if (j == 4)
              n4++;
            else
              n7++;
            int o = n - 1 - i;
            if (n4 + o >= n7 && n7 + o >= n4) {
              s[i] = j + '0';
              for (j = i + 1; j < n; j++) {
                s[j] = '4';
                n4++;
                o--;
                if (n7 + o < n4) {
                  s[j] = '7';
                  n4--;
                  n7++;
                }
              }
              puts(s);
              exit(0);
            }
          }
      }
  n++;
  if (n % 2 == 1) n++;
  for (i = 0; i < n; i++)
    if (i < n / 2)
      s[i] = '4';
    else
      s[i] = '7';
  puts(s);
  return 0;
}
