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.util.*;
import java.math.*;
import java.io.*; 
 public class Main{

    public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static FastReader scan = new FastReader();
    
static long mod=1000000000;
static int []dx={1,-1,0,0};
static int []dy={0,0,1,-1};
static int dx_8[]={1,1,1,0,0,-1,-1,-1};
static int dy_8[]={-1,0,1,-1,1,-1,0,1};
 static long powMod(long base, long exp, long mod) {
       if (base == 0 || base == 1) return base;
       if (exp == 0) return 1;
       if (exp == 1) return base % mod;
       long R = powMod(base, exp/2, mod) % mod;
       R *= R;
       R %= mod;
       if ((exp & 1) == 1) {
           return base * R % mod;
       }
       else return R % mod;
   }

     static long gcd(long a, long b) {
    if(a!=0&&b!=0)
        while((a%=b)!=0&&(b%=a)!=0);
    return a^b;
}  

static int n,m,d,st=0,en=0;
static char board[][];
static int dist[][];
static boolean e(int x,int y)
{
    return(x>=0&&x<m&&y>=0&&y<n&&board[x][y]=='.');
}
static int big=Integer.MAX_VALUE;
static void bfs(int x,int y)
{
     for(int row[]:dist)
        Arrays.fill(row,-1);
    Queue<Pair>dq=new LinkedList<Pair>();
    dq.add(new Pair(x,y));
    dist[x][y]=0;
    //out.println("FUCK");
    while(!dq.isEmpty()){
       // out.println("FUCK");
        Pair p=dq.remove();
        int xx=p.x,yy=p.y;
        for(int i=0;i<4;i++)
        {
            int nr=xx+dx[i],nc=yy+dy[i];
            //System.out.println("p.x "+nr+" "+nc+" "+dist[nr][nc]);
            if(nr>=m||nr<0||nc>=n||nc<0||board[nr][nc]!='.')
                continue;
            if(dist[nr][nc]==-1)
            {
               // out.println("FUCK");
                dist[nr][nc]=dist[xx][yy]+1;
               out.println(dist[nr][nc]);

                dq.add(new Pair(nr,nc));
            }
        }
    }

    d=0;
    for(int i=0;i<m;i++)
        for(int j=0;j<n;j++)
            if(dist[i][j]>d)
            {
               // out.println("FUCK "+dist[i][j]);
                d=dist[i][j];
                st=i;
                en=j;
            }
}
static ArrayList<Long>luckies=new ArrayList<Long>();
static void f(long x)
{
    if(x>=(long)1e10+5)
        return;
    luckies.add(x);
    f(10*x+7);
    f(10*x+4);
}

public static void main(String[] args)  throws Exception 
{
   // java.util.Scanner scan=new java.util.Scanner(new File("convention.in"));
//PrintWriter out = new PrintWriter (new FileWriter("convention.out"));
    //1 0 1 0
    int tt=1;
//tt=scan.nextInt();
  //  System.out.println(4444477777L<(long)1e10);
   f(0);
   //System.out.println(luckies.contains(4444477777L));
   //System.out.println(luckies.size());
   outer:while(tt-->0)
   {
    
 long n=scan.nextLong();
 ArrayList<Long>res=new ArrayList<Long>();
 for(long k:luckies)
 {
    int cnt1=0,cnt2=0;
    long cur=k;
    while(cur>0)
    {
        if(cur%10==7)
            cnt1++;
        else if(cur%10==4)
            cnt2++;
        cur/=10;
    }
    if(cnt1==cnt2)
    {
        res.add(k);
    }
 }
 //out.println(res.contains(4444477777L));
 Collections.sort(res);
 long prev=0;
 for(int i=0;i<res.size();i++)
 {
    if(res.get(i)>=n)
    {
        //out.println(res.get(i));
        prev=res.get(i);
        break;
    }
 }
 out.println(prev);


}

out.close();
//do something instead of nothing
}
 
static long power(long a,long b)
{
    if(b==0)
        return 1;
    long res=power(a,b/2);
    if(b%2==1)
        return res*res*a;
    else return res*res;
}
  /*static long power(long x,long y,long m) 
    { 
        if (y == 0) 
            return 1; 
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        return (y % 2 == 0) ? p : (x * p) % m; 
    } */
    static long power(long a,long b,long mod)
{
    if(b==0)
        return 1;
    long res=power(a,b/2,mod);
    res=(res*res)%mod;
    if(b%2==0)
        return res;
    else 
        return (res*a)%mod;
}
    public static class FastReader {
        BufferedReader br;
        StringTokenizer root;
        
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        boolean hasNext(){
            String line;
            try{
            while((line=br.readLine())!=null)
                return true;
        }
        catch (IOException e)
     {
         return false;
     }
         return false;  
        }
 
        String next() {
            while (root == null || !root.hasMoreTokens()) {
                try {
                    root = new StringTokenizer(br.readLine());
                } catch (Exception addd) {
                    addd.printStackTrace();
                }
            }
            return root.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (Exception addd) {
                addd.printStackTrace();
            }
            return str;
        }
         public int[] nextIntArray(int arraySize) {
            int array[] = new int[arraySize];
 
            for (int i = 0; i < arraySize; i++) {
                array[i] = nextInt();
            }
 
            return array;
        }

        public boolean ready() throws IOException {return br.ready();}
}
 public static class Pair implements Comparable<Pair>{
        public int x, y,z;
        public Pair(int x1, int y1) {
            x=x1;
            y=y1;
        }
         public Pair(int x1, int y1,int z) {
            x=x1;
            y=y1;
            this.z=z;
        }
        @Override
        public int hashCode() {
            return (int)(x + 31 * y);
        }
        public String toString() {
            return x + " " + y;
        }
        @Override
        public boolean equals(Object o){
            if (o == this) return true;
            if (o.getClass() != getClass()) return false;
            Pair t = (Pair)o;
            return t.x == x && t.y == y;
        }
        public int compareTo(Pair o){
            return o.y-y;
        }

}
static class Edge{
        int d,w;
        Edge(int d,int w)
        {
            this.d=d;
            this.w=w;
        }
    }
    //union find by rank 


   



}