#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
long long pw(long long b, long long p) {
  if (!p) return 1;
  long long sq = pw(b, p / 2);
  sq *= sq;
  if (p % 2) sq *= b;
  return sq;
}
vector<long long> vec;
void gen(long long x, int cnt4, int cnt7, int n) {
  if (cnt4 == cnt7 && x >= n) vec.push_back(x);
  if (x >= 1e10) return;
  gen(x * 10 + 4, cnt4 + 1, cnt7, n);
  gen(x * 10 + 7, cnt4, cnt7 + 1, n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  gen(0, 0, 0, n);
  sort(vec.begin(), vec.end());
  vector<long long>::iterator it = lower_bound(vec.begin(), vec.end(), n);
  cout << *it << endl;
  return 0;
}
