#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-9;
string make_least_47(int n) {
  string ret;
  for (int i = 0; i < (int)(n); i++) {
    ret += '4';
  }
  for (int i = 0; i < (int)(n); i++) {
    ret += '7';
  }
  return ret;
}
string make_least_47_2(int r4, int r7) {
  string ret;
  for (int i = 0; i < (int)(r4); i++) {
    ret += '4';
  }
  for (int i = 0; i < (int)(r7); i++) {
    ret += '7';
  }
  return ret;
}
int main(void) {
  string ns;
  cin >> ns;
  int N = ns.length();
  string ret;
  if (N & 1) {
    ret = make_least_47((N + 1) / 2);
    cout << ret << endl;
    return 0;
  }
  int c4 = 0;
  int c7 = 0;
  int last4 = -1;
  int last7 = -1;
  for (int i = 0; i < (int)(N); i++) {
    if (ns[i] == '4') {
      if (c4 == N / 2) {
        ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        break;
      }
      c4++;
      last4 = i;
      ret += ns[i];
    } else if (ns[i] == '7') {
      if (c7 == N / 2) {
        if (c4 == 0) {
          ret = make_least_47((N + 2) / 2);
        } else {
          c4 = c7 = 0;
          ret = "";
          if (last4 > last7) {
            last4 = last7;
            while (ns[last4] == '7') last4--;
          }
          for (int j = 0; j < (int)(last4); j++) {
            if (ns[j] == '4')
              c4++;
            else
              c7++;
            ret += ns[j];
          }
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        }
        break;
      }
      c7++;
      last7 = i;
      ret += ns[i];
    } else {
      if (ns[i] > '7') {
        if (c4 == 0 || (c7 == (N / 2) && last7 == (N / 2 - 1))) {
          ret = make_least_47((N + 2) / 2);
        } else {
          c4 = c7 = 0;
          ret = "";
          if (c7 == N / 2 && last4 > last7) {
            last4 = last7;
            while (ns[last4] == '7') last4--;
          }
          for (int j = 0; j < (int)(last4); j++) {
            if (ns[j] == '4')
              c4++;
            else
              c7++;
            ret += ns[j];
          }
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        }
      } else if (ns[i] < '4') {
        ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
      } else {
        if (last7 == (N / 2 - 1)) {
          ret = make_least_47((N + 2) / 2);
        } else if (c7 == N / 2) {
          c4 = c7 = 0;
          ret = "";
          if (last4 > last7) {
            last4 = last7;
            while (ns[last4] == '7') last4--;
          }
          for (int j = 0; j < (int)(last4); j++) {
            if (ns[j] == '4')
              c4++;
            else
              c7++;
            ret += ns[j];
          }
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        } else {
          ret += '7';
          c7++;
          ret += make_least_47_2(N / 2 - c4, N / 2 - c7);
        }
      }
      break;
    }
  }
  cout << ret << endl;
  return 0;
}
