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.PrintWriter;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.readInt();
        int nDigits = 0, nn = n;
        while (nn > 0) {
            ++nDigits;
            nn /= 10;
        }

        nDigits += (nDigits % 2);
        int[] a = new int[nDigits];
        for (int i = 0; i < nDigits / 2; ++i)
            a[i] = 4;
        for (int i = nDigits / 2; i < nDigits; ++i)
            a[i] = 7;

        while (value(a) < n) {
            int i = nDigits - 2;
            while (i >= 0 && a[i] >= a[i + 1]) --i;
            if (i < 0) break;
            int j = nDigits - 1;
            while (a[j] <= a[i]) --j;
            int temp = a[i];
            a[i] = a[j];
            a[j] = temp;
            ++i;
            j = nDigits - 1;
            while (i < j) {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
                ++i;
                --j;
            }
        }

        if (value(a) < n) {
            nDigits += 2;
            a = new int[nDigits];
            for (int i = 0; i < nDigits / 2; ++i)
                a[i] = 4;
            for (int i = nDigits / 2; i < nDigits; ++i)
                a[i] = 7;
        }
        out.println(value(a));
    }

    private long value(int[] a) {
        long res = 0;
        for (int v : a)
            res = 10 * res + v;
        return res;
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }