#include <bits/stdc++.h>
using namespace std;
inline int D() {
  int t;
  scanf("%d", &t);
  return t;
}
inline long long llD() {
  long long t;
  scanf("%lld", &t);
  return t;
}
long long sum1, sum2, x;
int cnt1, cnt2;
int main() {
  long long n = llD(), MX = LONG_LONG_MAX;
  for (int i = 1; i < (1 << 11); ++i) {
    sum1 = sum2 = 0, cnt1 = cnt2 = 0, x = i;
    while (x) {
      if (x & 1) {
        sum1 = sum1 * 10 + 4;
        sum2 = sum2 * 10 + 7;
        ++cnt1;
      } else {
        sum1 = sum1 * 10 + 7;
        sum2 = sum2 * 10 + 4;
        ++cnt2;
      }
      x >>= 1;
    }
    if (cnt1 == cnt2 && n <= sum1) MX = min(MX, sum1);
    if (cnt1 == cnt2 && n <= sum2) MX = min(MX, sum2);
  }
  printf("%lld\n", MX);
}
