#include <bits/stdc++.h>
using namespace std;
int indix;
void supperlucky(long long a[5000], int level, long long number, int n,
                 int four, int seven, int thiernumber) {
  if (level > n + 2) return;
  if (number >= thiernumber && four == seven) {
    a[indix] = number;
    indix++;
  }
  supperlucky(a, level + 1, number * 10 + 4, n, four + 1, seven, thiernumber);
  supperlucky(a, level + 1, number * 10 + 7, n, four, seven + 1, thiernumber);
}
int main() {
  int thiernumer, temp, n = 0;
  cin >> thiernumer;
  temp = thiernumer;
  while (temp > 0) {
    n++;
    temp /= 10;
  }
  long long s = pow(2, n + 3) - pow(2, n), a[s];
  supperlucky(a, 0, 0, n, 0, 0, thiernumer);
  sort(a, a + indix);
  cout << a[0];
  return 0;
}
