#include <bits/stdc++.h>
using namespace std;
long long n, i, t, k, j, m;
int main() {
  vector<vector<long long> > v(10);
  v[0].push_back(4);
  v[0].push_back(7);
  for (i = 1; i < 10; i++) {
    for (j = 0; j < v[i - 1].size(); j++) {
      long long x = v[i - 1][j];
      v[i].push_back(x * 10 + 4);
      v[i].push_back(x * 10 + 7);
    }
  }
  cin >> n;
  i = 0;
  j = 0;
  while (1) {
    if (v[i][j] < n) {
      j++;
    } else {
      long long f = 0, s = 0;
      long long a = v[i][j];
      while (a) {
        if (a % 10 == 4) {
          f++;
        } else {
          s++;
        }
        a = a / 10;
      }
      if (f == s) {
        cout << v[i][j];
        break;
      } else {
        j++;
      }
    }
    if (j >= v[i].size()) {
      j = 0;
      i++;
    }
  }
}
