#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
const long long mod = 1e7;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, i = 0ll, d = 0ll, c, f, s;
  cin >> n;
  while (1) {
    c = f = s = 0;
    for (int j = 0ll, t = 1ll; j < d; ++j, t *= 10ll)
      if (i & (1ll << j))
        c += 7ll * t, s++;
      else
        c += 4ll * t, f++;
    if (c >= n && s == f) {
      cout << c;
      return 0;
    }
    i++;
    if (!((i + 1ll) & (i))) d++;
  }
  return 0;
}
