#include <bits/stdc++.h>
using namespace std;
long long sum = 0, x, ans = 1LL << 60;
void solve(long long sum, long long seven, long long four) {
  if (sum >= x && seven == four) {
    ans = min(ans, sum);
  }
  if (sum > x * 100) {
    return;
  }
  solve(sum * 10 + 4, seven, four + 1);
  solve(sum * 10 + 7, seven + 1, four);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> x;
  solve(0, 0, 0);
  cout << ans << '\n';
  return 0;
}
