#include <bits/stdc++.h>
using namespace std;
long long n, s;
void dfs(long long x, long long s4, long long s7) {
  if (n <= x && (x < s || s == 0) && s4 == s7) s = x;
  if (x <= n * 100) {
    dfs(x * 10 + 4, s4 + 1, s7);
    dfs(x * 10 + 7, s4, s7 + 1);
  }
}
int main() {
  cin >> n;
  dfs(0, 0, 0);
  if (n <= 47) s = 47;
  cout << s;
}
