#include <bits/stdc++.h>
using namespace std;
string n;
char ans[100005];
int four;
int seven;
bool vec;
bool danger;
void dfs(int x) {
  if (vec == true) return;
  if (four == seven && x == (int)n.length()) {
    vec = true;
    return;
  }
  if (x == (int)n.length()) return;
  if (danger == true) {
    if (n[x] > '7')
      return;
    else if (n[x] == '7') {
      ans[x] = '7';
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      seven--;
    } else if (n[x] > '4') {
      danger = false;
      ans[x] = '7';
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      seven--;
      danger = true;
    } else if (n[x] == '4') {
      ans[x] = '4';
      four++;
      dfs(x + 1);
      if (vec == true) return;
      four--;
      ans[x] = '7';
      danger = false;
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      seven--;
      danger = true;
    } else {
      ans[x] = '4';
      danger = false;
      four++;
      dfs(x + 1);
      if (vec == true) return;
      four--;
      danger = true;
      ans[x] = '7';
      danger = false;
      seven++;
      dfs(x + 1);
      if (vec == true) return;
      danger = true;
      seven--;
    }
  } else {
    if ((seven - four + (int)n.length() - x) % 2 == 0 &&
        (seven - four + (int)n.length() - x) >= 0 &&
        (four + (int)n.length() - x - seven) % 2 == 0 &&
        (four + (int)n.length() - x - seven) >= 0 &&
        (seven + four + (int)n.length() - x) / 2 == (int)n.length() / 2) {
      for (int ii = 0; ii < (seven - four + (int)n.length() - x) / 2; ii++) {
        ans[x + ii] = '4';
      }
      for (int ii = 0; ii < (four + (int)n.length() - x - seven) / 2; ii++) {
        ans[x + ii + (seven - four + (int)n.length() - x) / 2] = '7';
      }
      vec = true;
      return;
    } else {
      return;
    }
  }
}
int main() {
  cin >> n;
  memset(ans, '\0', sizeof(ans));
  four = 0;
  seven = 0;
  vec = false;
  danger = false;
  if ((int)n.length() % 2 == 0 && n[0] > '7') n += '1';
  if ((int)n.length() % 2 == 1) {
    for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
      ans[i] = '4';
    }
    for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
      ans[i + ((int)n.length() + 1) / 2] = '7';
    }
    puts(ans);
  } else {
    danger = true;
    dfs(0);
    if (vec == true)
      puts(ans);
    else {
      n += '1';
      for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
        ans[i] = '4';
      }
      for (int i = 0; i < ((int)n.length() + 1) / 2; i++) {
        ans[i + ((int)n.length() + 1) / 2] = '7';
      }
      puts(ans);
    }
  }
  return 0;
}
