#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
int main() {
  string str, ans;
  int n, idx, a, b;
  cin >> str, n = str.size();
  if (n % 2 || str > (string(n >> 1, '7') + string(n >> 1, '4')))
    cout << string(n / 2 + 1, '4') + string(n / 2 + 1, '7') << endl;
  else {
    if (n & 1) n++, str += '0';
    ans = string(n >> 1, '4') + string(n >> 1, '7'), idx = a = b = n >> 1;
    for (long long i = 0; i < int(n); i++)
      if (str[i] == '4' || str[i] == '7')
        ans[i] = str[i];
      else if (str[i] < '4') {
        ans[i] = '4', idx = i + 1;
        for (long long j = 0; j < int(i + 1); j++) ans[j] == '4' ? a-- : b--;
        while (a) a--, ans[idx++] = '4';
        while (b) b--, ans[idx++] = '7';
        break;
      } else if (str[i] < '7') {
        ans[i] = '7', idx = i + 1;
        for (long long j = 0; j < int(i + 1); j++) ans[j] == '4' ? a-- : b--;
        while (a) a--, ans[idx++] = '4';
        while (b) b--, ans[idx++] = '7';
        break;
      } else {
        for (long long j = i - 1; j > -1; j--)
          if (ans[j] == '4') {
            ans[j] = '7';
            for (long long k = 0; k < int(j + 1); k++)
              ans[k] == '4' ? a-- : b--;
            for (long long k = j + 1; k < n; k++)
              if (a)
                ans[k] = '4', a--;
              else
                ans[k] = '7';
            break;
          }
        break;
      }
    a = b = 0;
    for (long long i = 0; i < int(n); i++) ans[i] == '4' ? a++ : b++;
    if (a != b)
      if (a < b) {
        int tmp = n / 2 - a + 1, now = 0;
        for (long long i = n - 1; i > -1; i--)
          if (ans[i] == '7')
            now++;
          else if (now >= tmp) {
            ans[i] = '7';
            for (long long j = i + 1; j < n; j++)
              if (ans[j] == '7' && tmp)
                tmp--, ans[j] = '4';
              else if (!tmp)
                break;
            break;
          }
      } else {
        int tmp = n / 2 - b;
        for (long long i = n - 1; i > -1; i--)
          if (ans[i] == '4' && tmp)
            tmp--, ans[i] = '7';
          else if (!tmp)
            break;
      }
  hell:
    cout << ans << endl;
  }
  return 0;
}
