#include <bits/stdc++.h>
using namespace std;
struct _ {
  _() { ios_base::sync_with_stdio(0); }
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
  o << "(" << t.first << ", " << t.second << ")";
  return o;
}
template <class T>
void PV(T a, T b, int n = 0) {
  int c = 0;
  while (a < b) {
    cout << *a++;
    if (a < b && (n == 0 || ++c % n))
      cout << " ";
    else
      cout << endl;
  }
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool chmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
string tostring(T first, int len = 0) {
  stringstream ss;
  ss << first;
  string r = ss.str();
  if (r.length() < len) r = string(len - r.length(), '0') + r;
  return r;
}
template <class T>
void convert(string first, T &r) {
  stringstream ss(first);
  ss >> r;
}
const long long linf = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int N = 111111;
vector<int> n;
int m;
vector<string> vs;
int path[N];
bool dfs(int n4, int n7, int e) {
  if (n4 > n.size() / 2 || n7 > n.size() / 2) return 0;
  if (n4 + n7 == n.size()) {
    if (n4 != n7) {
      return 0;
    } else {
      if (n4 == n7) {
        string s;
        for (int i = 0; i < n4 + n7; i++) s += path[i] + '0';
        vs.push_back(s);
        return 1;
      }
    }
  }
  if (e == 0) {
    int rn4 = n.size() / 2 - n4;
    int rn7 = n.size() / 2 - n7;
    string s;
    for (int i = 0; i < n4 + n7; i++) s += path[i] + '0';
    s += string(rn4, '4') + string(rn7, '7');
    vs.push_back(s);
    return 1;
  } else {
    if (n[n4 + n7] > 7) {
      return 0;
    } else if (n[n4 + n7] > 4) {
      path[n4 + n7] = 7;
      if (dfs(n4, n7 + 1, n[n4 + n7] == 7)) return 1;
    } else {
      path[n4 + n7] = 4;
      if (dfs(n4 + 1, n7, n[n4 + n7] == 4)) return 1;
      path[n4 + n7] = 7;
      if (dfs(n4, n7 + 1, n[n4 + n7] == 7)) return 1;
    }
  }
  return 0;
}
int main() {
  string s;
  cin >> s;
  for (auto i : s) n.push_back(i - '0');
  if (n.size() % 2 == 0) dfs(0, 0, 1);
  reverse((n).begin(), (n).end());
  n.push_back(0);
  reverse((n).begin(), (n).end());
  if (n.size() % 2 == 0) dfs(0, 0, 1);
  reverse((n).begin(), (n).end());
  n.push_back(0);
  reverse((n).begin(), (n).end());
  if (n.size() % 2 == 0) dfs(0, 0, 1);
  string best = vs[0];
  for (int i = 1; i < vs.size(); i++) {
    if (best.length() > vs[i].length())
      best = vs[i];
    else if (best.length() == vs[i].length())
      chmin(best, vs[i]);
  }
  cout << best << endl;
  return 0;
}
