#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int bit[N], n;
long long ans = (long long)1e18 + 1;
void dfs(long long num, int p, int c4, int c7) {
  if (num > ans) return;
  if (c4 == c7 && num >= n) {
    ans = num;
    return;
  }
  bit[p] = 4;
  dfs(num * 10 + 4, p + 1, c4 + 1, c7);
  bit[p] = 7;
  dfs(num * 10 + 7, p + 1, c4, c7 + 1);
}
int main() {
  scanf("%d", &n);
  dfs(0, 1, 0, 0);
  cout << ans << endl;
  return 0;
}
