#include <bits/stdc++.h>
using namespace std;
long long n, m, t, i, j, x, y, s;
int main() {
  cin >> n;
  for (;;) {
    m += 2;
    for (i = 0; i < (1 << m); i++) {
      t = i;
      x = 0;
      y = 0;
      s = 0;
      for (j = 1 << (m - 1); j; j = (j >> 1))
        if (t & j) {
          s = s * 10 + 7;
          x++;
        } else {
          s = s * 10 + 4;
          y++;
        }
      if (x == y && s >= n) {
        cout << s;
        return 0;
      }
    }
  }
  return 0;
}
