#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int n = s.size();
  for (int i = n - 1; i > 0; --i) {
    if (s[i] <= '4')
      s[i] = '4';
    else if (s[i] <= '7')
      s[i] = '7';
    else {
      s[i] = '7';
      s[i - 1] += 1;
    }
  }
  int k = 0;
  if (s[0] > '9') {
    n++;
    s = "";
    for (int i = 0; i < n; ++i) {
      s += '4';
    }
  }
  int no = 0, no1 = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '4')
      no++;
    else
      no1++;
  }
  if (n % 2) {
    s = "4";
    n++;
    for (int i = 0; i < n / 2 - 1; ++i) {
      s += '4';
    }
    for (int i = 0; i < n / 2; ++i) {
      s += '7';
    }
  } else {
    if (no > no1) {
      for (int i = n - 1; i >= 0 && no != no1; --i) {
        if (s[i] == '4') {
          s[i] = '7';
          no--, no1++;
        }
      }
    } else if (no1 > no) {
      int pos = -1;
      for (int i = 0; i < n; ++i) {
        if (s[i] == '4') {
          pos = i;
          break;
        }
      }
      if (pos == -1 || n - pos - 1 < no1 - no) {
        s = "44";
        for (int i = 0; i < n / 2 - 1; ++i) {
          s += "4";
        }
        for (int i = 0; i < n / 2 + 1; ++i) {
          s += '7';
        }
      } else {
        s[pos] = '7';
        int i = pos;
        no--, no1++, i++;
        while (no != no1) {
          if (s[i] == '7') s[i] = '4', no++, no1--;
          i++;
        }
        sort(s.begin() + pos, s.end());
      }
    }
  }
  cout << s;
  return 0;
}
