#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int M = 2e5 + 7;
const int inf = 1e9 + 7;
const long long base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;
string s;
int last = 0;
int ans[N];
void solve() {
  cin >> s;
  if (s.size() % 2 == 1) {
    int t = (s.size() + 1) / 2;
    for (int i = 0; i < t; i++) printf("%d", 4);
    for (int i = 0; i < t; i++) printf("%d", 7);
    return;
  }
  bool bg = false;
  for (int i = 1; i < s.size() + 1; i++) {
    if (bg) {
      ans[i] = 4;
    } else {
      int c = s[i - 1] - '0';
      if (c <= 4) {
        ans[i] = 4;
        if (c < 4) bg = true;
      } else {
        if (c <= 7) {
          ans[i] = 7;
          if (c < 7) bg = true;
        } else {
          if (ans[last] == 0)
            ans[last] = 4;
          else
            ans[last] = 7;
          bg = true;
          for (int j = last + 1; j < i + 1; j++) ans[j] = 4;
        }
      }
    }
    if (!bg && ans[i] == 4) last = i;
  }
  int cnt4 = 0, cnt7 = 0;
  for (int i = 0; i < s.size() + 1; i++)
    if (ans[i] == 4)
      cnt4++;
    else if (ans[i] == 7)
      cnt7++;
  if ((cnt4 + cnt7) % 2 == 1 || cnt4 == 0) {
    int t = (cnt4 + cnt7 + 1) / 2;
    if (cnt4 == 0) t++;
    for (int i = 0; i < t; i++) printf("%d", 4);
    for (int i = 0; i < t; i++) printf("%d", 7);
    return;
  }
  for (int i = s.size(); i >= 0; i--) {
    if (cnt7 >= cnt4) {
      break;
    }
    if (ans[i] == 4) {
      ans[i] = 7;
      cnt7++;
      cnt4--;
    }
  }
  if (cnt4 < cnt7) {
    int j = -1;
    int dem = 0;
    for (int i = s.size(); i > -1; i--) {
      if (ans[i] == 7)
        dem++;
      else {
        if (ans[i] == 4 && cnt4 + dem - 1 >= cnt7 - dem + 1) {
          ans[i] = 7;
          j = i;
          cnt4--;
          cnt7++;
          break;
        }
      }
    }
    if (j == -1) {
      int t = (cnt4 + cnt7 + 2) / 2;
      for (int i = 0; i < t; i++) cout << 4;
      for (int i = 0; i < t; i++) cout << 7;
      return;
    }
    for (int i = j + 1; i < s.size() + 1; i++) {
      if (cnt4 == cnt7) break;
      if (ans[i] == 7) {
        ans[i] = 4;
        cnt4++;
        cnt7--;
      }
    }
  }
  for (int i = 0; i <= s.size(); i++)
    if (ans[i] != 0) printf("%d", ans[i]);
}
int main() { solve(); }
