#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.14159265358979;
const long long mod = 1e9 + 7;
long long ans = LLONG_MAX;
long long in;
void f(long long n, int four, int sev) {
  if (n > 1e11) return;
  if (n >= in) {
    if (four == sev) ans = min(ans, n);
  }
  f(n * 10 + 4, four + 1, sev);
  f(n * 10 + 7, four, sev + 1);
}
void solve(int test_case) {
  cin >> in;
  f(0, 0, 0);
  cout << ans;
}
int main() {
  int t = 1;
  for (int i = 0; i < t; i++) solve(i);
  return 0;
}
