Problem: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.

Output

Output the least super lucky number that is more than or equal to n.

Examples

Input

4500


Output

4747


Input

47


Output

47

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BLuckyNumbersEasy solver = new BLuckyNumbersEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class BLuckyNumbersEasy {
        static int count(StringBuilder s, char b) {
            int a = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == b) {
                    a++;
                }
            }
            return a;
        }

        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            StringBuilder s = new StringBuilder(sc.nextLine());
            StringBuilder tmp;
            int initial = Integer.parseInt(s.toString());
            int n = s.length();
            long ans = Long.MAX_VALUE;
            for (int j = 0; j < (1 << n); j++) {
                tmp = new StringBuilder(s);
                for (int i = n - 1; i >= 0; i--) {
                    if ((j & 1 << i) > 0) {
                        tmp.setCharAt(i, '4');
                    } else {
                        tmp.setCharAt(i, '7');
                    }
                }
                if (count(tmp, '4') == count(tmp, '7') && Long.parseLong(tmp.toString()) >= initial) {
                    ans = Math.min(ans, Long.parseLong(tmp.toString()));
                }
            }
            if (ans == Long.MAX_VALUE) {
                StringBuilder res = new StringBuilder();
                if (n % 2 == 1) {
                    for (int i = 0; i < (n + 1) / 2; i++) {
                        res.append('4');
                    }
                    for (int i = 0; i < (n + 1) / 2; i++) {
                        res.append('7');
                    }
                } else {
                    for (int i = 0; i < (n + 2) / 2; i++) {
                        res.append('4');
                    }
                    for (int i = 0; i < (n + 2) / 2; i++) {
                        res.append('7');
                    }
                }
                out.println(res);
                return;
            }
            out.println(ans);
        }

    }

    static class inputClass {
        BufferedReader br;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}