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 PYTHON3):

Solution:
from itertools import permutations
def check(n,giv):
    if n%2==0:
        f=[]
        for i in range(n):
            if i%2==0:
                f.append(4)
            else:
                f.append(7)
        f=list(permutations(f))
        ans=[]
        for  i in f:
            ans1=''
            if i[0]==0:
                continue
                
            for j in i:
                ans1+=str(j)
            ans.append(int(ans1))
        #print(ans)
        mini,number=float('inf'),0
        for i in ans:
            if i>giv and i-giv<mini:
                mini=i-giv
                number=i
        return number
        
                
        
    
        
        
            
            
def l():
    return list(map(int,input().rstrip().split()))
def ini():
    return int(input())
def te():
    return list(map(int,input().split()))
def st():
    return input().rstrip()
giv=int(input())
n=len(str(giv))
if giv==10**9:
    ans=''
    for i in range(len(str(giv))):
        if i<n//2:
            ans+='4'
        else:
            ans+='7'
    print(ans)
    exit()
s=str(giv)

y=s

if y.count('7')==y.count('4') and y.count('7')+y.count('4')==len(y):
    print(y)
else:
    n=len(s)
    
    if n%2==0:
        if s[0]<'7':
            print(check(n,giv))
            exit()
        y=check(n,giv)
        if y!=0:
            print(y)
        else:
            ans=''
            for i in range(n+2):
                if i<=n//2:
                    ans+='4'
                else:
                    ans+='7'
            print(ans)
    else:
        ans=''
        for i in range(n+1):
            if i<=n//2:
                ans+='4'
            else:
                ans+='7'
        print(ans)