#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll f = n/4;
    n = n % 4;
    ll s = n / 7;
    n = n % 7;
    ll ans = 0;
    while(n != 0 && n % 7 != 0){
        n += 4;
        ans++;
        if(ans > f){
            cout<<-1<<"\n";
            return 0;
        }
    }
    f = f - ans;
    s += n/7;
    for(ll i = 0 ; i < f; i++){
        cout<<4;
    }
    for(ll i = 0 ; i < s; i++){
        cout<<7;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>

const int MOD = 1000000007;
const ll MAX = 2005;
int arr[MAX];

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf("%c", &arr[i]); }

#define f first
#define s second

int main() {
    int x; cin >> x;
    if (x == 1 || x == 2 || x == 3 || x == 5 || x == 6 || x == 9 || x == 10 || x == 13 || x == 17) { cout << -1; return 0;}
    if (x == 4) { cout << 4; return 0;}
    if (x == 7) { cout << 7; return 0;}
    if (x == 8) { cout << 44; return 0;}
    if (x == 11) { cout << 47; return 0;}
    if (x == 12) { cout << 444; return 0;}
    if (x == 14) { cout << 77; return 0;}
    if (x == 15) { cout << 447; return 0;}
    if (x == 16) { cout << 4444; return 0;}
    for (int i=1000000; i >=0; i--) {
        if ((x-7*i)%4==0 && (x-7*i)/4 >= 0) {
            F0R(ea, (x-7*i)/4) { cout << 4; }
            F0R(ea, i) { cout << 7; }
            return 0;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>

const int MOD = 1000000007;
const ll MAX = 2005;
int arr[MAX];

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf("%c", &arr[i]); }

#define f first
#define s second

int main() {
    int x; cin >> x;
    if (x == 1 || x == 2 || x == 3 || x == 5 || x == 6 || x == 8 || x == 9 || x == 10 || x == 13 || x == 17) { cout << -1; return 0;}
    if (x == 4) { cout << 4; return 0;}
    if (x == 7) { cout << 7; return 0;}
    if (x == 11) { cout << 47; return 0;}
    if (x == 12) { cout << 444; return 0;}
    if (x == 14) { cout << 77; return 0;}
    if (x == 15) { cout << 447; return 0;}
    if (x == 16) { cout << 4444; return 0;}
    for (int i=1000000; i >=0; i--) {
        if ((x-7*i)%4==0 && (x-7*i)/4 >= 0) {
            F0R(ea, (x-7*i)/4) { cout << 4; }
            F0R(ea, i) { cout << 7; }
            return 0;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>

const int MOD = 1000000007;
const ll MAX = 2005;
int arr[MAX];

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf("%c", &arr[i]); }

#define f first
#define s second

int main() {
    int x; cin >> x;
    if (x == 1 || x == 2 || x == 3 || x == 5 || x == 6 || x == 8 || x == 9 || x == 10 || x == 13 || x == 17) { cout << -1; return 0;}
    if (x == 4) { cout << 4; return 0;}
    if (x == 7) { cout << 7; return 0;}
    if (x == 11) { cout << 47; return 0;}
    if (x == 12) { cout << 444; return 0;}
    if (x == 14) { cout << 77; return 0;}
    if (x == 15) { cout << 447; return 0;}
    if (x == 16) { cout << 4444; return 0;}
    F0R(i, 1000000) {
        if ((x-7*i)%4==0) {
            F0R(ea, (x-7*i)/4) { cout << 4; }
            F0R(ea, i) { cout << 7; }
            return 0;
        }
    }
}


#include<bits/stdc++.h>
#define         sz          100010*2

using namespace std;

vector<pair<int,int>>v;

int main()
{
    int n,a,x,y,mx;
    scanf("%d",&n);

    int flag = 0;

    mx = 10000000;
    x = 0;y = 0;

    for(int i=1;i<1000010;i++){
        a = abs(n-(i*7))/4;

        if((a*4)+(i*7)==n){
            v.push_back({a,i});
            flag = 1;
        }
    }

    if(flag == 1){
        for(int i=0;i<v.size();i++){
            if(v[i].first+v[i].second<mx) {
                x = v[i].first;
                y = v[i].second;
            }
        }

        while(x--) printf("%d",4);
        while(y--) printf("%d",7);
        printf("\n");
    }else{
        printf("-1\n");
    }

    return 0;
}


#include<bits/stdc++.h>
#define         sz          100010*2

using namespace std;

vector<pair<int,int>>v;

int main()
{
    int n,a,x,y,mx;
    scanf("%d",&n);

    int flag = 0;

    mx = 10000000;
    x = 0;y = 0;

    if(n==4 || n==7){ printf("%d\n",n); return 0;}

    for(int i=1;i<1000010;i++){
        a = abs(n-(i*7))/4;

        if((a*4)+(i*7)==n){
            v.push_back({a,i});
            flag = 1;
        }
    }

    if(flag == 1){
        for(int i=0;i<v.size();i++){
            if(v[i].first+v[i].second<mx) {
                x = v[i].first;
                y = v[i].second;
            }
        }

        while(x--) printf("%d",4);
        while(y--) printf("%d",7);
        printf("\n");
    }else{
        printf("-1\n");
    }

    return 0;
}


#include<bits/stdc++.h>
#define         sz          100010*2

using namespace std;

vector<pair<int,int>>v;

int main()
{
    int n,a,x,y,mx;
    scanf("%d",&n);

    int flag = 0;

    mx = 10000000;
    x = 0;y = 0;

    if(n==4 || n==7){ printf("%d\n",n); return 0;}

    for(int i=0;i<1000010;i++){
        a = abs(n-(i*7))/4;

        if((a*4)+(i*7)==n){
            v.push_back({a,i});
            flag = 1;
        }
    }

    if(flag == 1){
        for(int i=0;i<v.size();i++){
            if(v[i].first+v[i].second<mx) {
                x = v[i].first;
                y = v[i].second;
            }
        }

        while(x--) printf("%d",4);
        while(y--) printf("%d",7);
        printf("\n");
    }else{
        printf("-1\n");
    }

    return 0;
}


#include<bits/stdc++.h>
#define         sz          100010*2

using namespace std;

vector<pair<int,int>>v;

int main()
{
    int n,a;
    scanf("%d",&n);

    int flag = 0;

    for(int i=1;i<1000010;i++){
        a = abs(n-(i*7))/4;

        if((a*4)+(i*7)==n){
            v.push_back({a,i});
            flag = 1;
        }
    }

    if(flag == 1){
        sort(v.begin(),v.end());

        int x = v[v.size()-1].first;
        int y = v[v.size()-1].second;

        while(x--) printf("%d",4);
        while(y--) printf("%d",7);
        printf("\n");
    }else{
        printf("-1\n");
    }

    return 0;
}


#include <bits/stdc++.h>
#define task "84C"
using namespace std;
const int MAX = 1e6 + 7;
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define fi first
#define se second
int main ()
{
	//fastio;
	//freopen (task ".INP", "r", stdin);
	//freopen (task ".OUT", "w", stdout);
	int n;
	cin >> n;
	if(n%7==0) FOR(i,1,n/7) cout << 7;
	else if(n%4==0) FOR(i,1,n/4) cout << 4;
	else {
        int q=1,k=1;
        while(7*q+4*k<n) q++,k++;
        if((7*q+4*k-n)%7==0) {
            q--;
            FOR(i,1,k) cout << 4;
            FOR(i,1,q) cout << 7;
        }
        else if((7*q+4*k-n)%4==0) {
            k--;
            FOR(i,1,k) cout << 4;
            FOR(i,1,q) cout << 7;
        }
        else cout << -1;
	}
	return 0;
}


#include <bits/stdc++.h>
#define task "84C"
using namespace std;
const int MAX = 1e6 + 7;
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define fi first
#define se second
int main ()
{
	int n;
	int cnt4=0;
	int cnt7=0;
	cin >> n;
    while(n) {
        if(n<7&&n!=4) {
            cout << -1;
            exit(0);
        }
        else if(n%7==0) {
            n-=7;
            cnt7++;
        }
        else {
            n-=4;
            cnt4++;
        }
    }
    FOR(i,1,cnt4) cout << 4;
    FOR(i,1,cnt7) cout << 7;
	return 0;
}


#include <bits/stdc++.h>
#define task "84C"
using namespace std;
const int MAX = 1e6 + 7;
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define fi first
#define se second
int main ()
{
	//fastio;
	//freopen (task ".INP", "r", stdin);
	//freopen (task ".OUT", "w", stdout);
	int n;
	cin >> n;
	if(n%7==0) FOR(i,1,n/7) cout << 7;
	else if(n%4==0) FOR(i,1,n/4) cout << 4;
	else {
        int q=1,k=1;
        while(7*q+4*k<n) q++,k++;
        if(7*q+4*k==n) {
            FOR(i,1,k) cout << 4;
            FOR(i,1,q) cout << 7;
        }
        else {
            if((7*q+4*k-n)%7==0) {
                q--;
                FOR(i,1,k) cout << 4;
                FOR(i,1,q) cout << 7;
            }
            else if((7*q+4*k-n)%4==0) {
                k--;
                FOR(i,1,k) cout << 4;
                FOR(i,1,q) cout << 7;
            }
            else cout << -1;
        }
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
//map<ll , ll>m;
ll n , m;
vector<ll>a;
vector<ll>d;
ll MAX = 1e18;

int main()
{
   ll n;
   cin >> n;
   ll length = 1e18;
   for(ll i = 0 ; i <= 1000000 ; i++)
   {
       ll ans  =0;
       ll div = 11*i;
       ans = i*2;
       if(div > n)
       break;
       ll left = n - div;
       if(left%4 == 0)
       {
           ans += (left/4);
           length = min(ans , length);
       }
       else if(left%7 == 0)
       {
           ans += (left/7);
           length = min(ans , length);
       }
   }

   if(length == 1e18)
   {
       cout << -1;
       return 0;
   }

   for(ll i = 0 ; i <= 1000000 ; i++)
   {
       ll ans  = 0;
       ll div = 11*i;
       ans = i*2;
       if(div > n)
       break;
       ll left = n - div;
       if(left%4 == 0 && length == (ans + (left/4)))
       {
           string x;
           for(ll j = 0 ; j < (left/4) ; j++)
           x.push_back(52);

           for(ll j = 0 ; j  < i ; j++)
           {
               x.push_back(52);
               x.push_back(55);
           }

           sort(x.begin()  ,x.end());
           cout << x;
           return 0;
       }
       else if(left%7 == 0 && length == (ans + (left/7)))
       {
           string x;

           for(ll j = 0 ; j  < i ; j++)
           {
               x.push_back(52);
               x.push_back(55);
           }
           for(ll j = 0 ; j < (left/7) ; j++)
           x.push_back(55);
           sort(x.begin()  ,x.end());
           cout << x;
           return 0;
       }
   }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
//map<ll , ll>m;
ll n , m;
vector<ll>a;
vector<ll>d;
ll MAX = 1e18;

int main()
{
   ll n;
   cin >> n;

   for(ll i = 1 ; i <= 1000000 ; i++)
   {
       ll div = 11*i;
       if(div > n)
       break;
       ll left = n - div;
       if(left%4 == 0)
       {
           string ans;
           for(ll j = 0 ; j < (left/4) ; j++)
           ans.push_back(52);

           for(ll j = 0 ; j < i ; j++)
           {
               ans.push_back(52);
               ans.push_back(55);
           }
           sort(ans.begin() , ans.end());
           cout << ans;
           return 0;
       }
       else if(left%7 == 0)
       {
           string ans;

           for(ll j = 0 ; j < i ; j++)
           {
               ans.push_back(52);
               ans.push_back(55);
           }
           for(ll j = 0 ; j < (left/7) ; j++)
           ans.push_back(55);
           sort(ans.begin() , ans.end());
           cout << ans;
           return 0;
       }
   }

   cout << -1;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
//map<ll , ll>m;
ll n , m;
vector<ll>a;
vector<ll>d;
ll MAX = 1e18;

int main()
{
   ll n;
   cin >> n;

   ll ans1 = 0 , ans2 = 0;
   ans1 =  (n/11);
   n -= (n/11)*11;
     string x;
   if(n%4 == 0)
   {
       ll ans2 = n/4;

       for(ll i =0 ; i < ans2 ; i++)
       {
           x.push_back(52);
       }
       for(ll i = 0 ;i < ans1 ; i++)
       {
           x.push_back(52);
           x.push_back(55);
       }
       cout << x ;
   }
   else if(n%7 == 0)
   {
       ll ans2 = n/7;

       for(ll i = 0 ;i < ans1 ; i++)
       {
           x.push_back(52);
           x.push_back(55);
       }

       for(ll i =0 ; i < ans2 ; i++)
       {
           x.push_back(55);
       }
       cout << x ;
   }
   else
   cout << -1;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
//map<ll , ll>m;
ll n , m;
vector<ll>a;
vector<ll>d;
ll MAX = 1e18;

int main()
{
   ll n;
   cin >> n;
   ll length = 1e18;
   for(ll i = 0 ; i <= 1000000 ; i++)
   {
       ll ans  =0;
       ll div = 11*i;
       ans = i*2;
       if(div > n)
       break;
       ll left = n - div;
       if(left%7 == 0)
       {
           ans += (left/7);
           length = min(ans , length);
       }

       else if(left%4 == 0)
       {
           ans += (left/4);
           length = min(ans , length);
       }

   }
   //cout << length << endl;
   if(length == 1e18)
   {
       cout << -1;
       return 0;
   }

   for(ll i = 0 ; i <= 1000000 ; i++)
   {
       ll ans  = 0;
       ll div = 11*i;
       ans = i*2;
       if(div > n)
       break;
       ll left = n - div;

       if(left%7 == 0 && length == (ans + (left/7)))
       {
           string x;

           for(ll j = 0 ; j  < i ; j++)
           {
               x.push_back(52);
               x.push_back(55);
           }
           for(ll j = 0 ; j < (left/7) ; j++)
           x.push_back(55);
           sort(x.begin()  ,x.end());
           cout << x;
           return 0;
       }

       else if(left%4 == 0 && length == (ans + (left/4)))
       {
           string x;
           for(ll j = 0 ; j < (left/4) ; j++)
           x.push_back(52);

           for(ll j = 0 ; j  < i ; j++)
           {
               x.push_back(52);
               x.push_back(55);
           }

           sort(x.begin()  ,x.end());
           cout << x;
           return 0;
       }

   }

}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int64 ll;

int main()
{
    int n;
    scanf("%d",&n);
   int t1=n/7;
   int t2=n%7;
   int t3=0;
   int ans4=1e8,ans7=1e8;
   for(int i=0;i<=t1;i++)
   {
       int tmp=n-i*7;
       if(tmp%4==0)
       {
           int tmp3=tmp/4;
           if(tmp3+i<(ans4+ans7))
           {
               ans7=i;
               ans4=tmp3;
           }
       }
   }
   //printf("%d  %d\n",ans4,ans7);
    if(ans4==1e8&&ans7==1e8) printf("-1\n");
    else
  {
   for(int i=1;i<=ans4;i++) printf("4");
   for(int i=1;i<=ans7;i++) printf("7");
   printf("\n");
  }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

int main()
{
    int i,j,k,f=0,t;
    int n;
    scanf("%d",&n);
    if(n%7==0){
        k=n/7;
        for(i=1;i<=k;i++)printf("7");
        cout<<endl;
        return 0;
    }
    k=n/7;
    for(i=k;i>=0;i--){
        j=n-i*7;
        if(j%4==0){
            f=1;
            break;
        }
    }
    t=i;
    if(f==0){cout<<-1<<endl;return 0;}
    j=j/4;
    for(i=1;i<=j;i++){
        printf("4");
    }
    if(t!=0)for(i=1;i<=t;i++)printf("7");
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[6030][6000];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=100000;i++)
    {
        if((n-i*4)<0)
            break;
        if((n-i*4)%3==0&&(n-i*4)/3<=i)
        {
            int ans=(n-i*4)/3;
            for(int j=0;j<i-ans;j++)
                printf("4");
            for(int j=0;j<ans;j++)
                printf("7");
            puts("");
            return 0;
        }
    }
    puts("-1");
}


#include<stdio.h>
#include<algorithm>
using namespace std;
struct node
{
    int v,n4,n7;
    friend bool operator <(node a,node b)
    {
        return a.v<b.v;
    }
};
int main()
{
    int n;
    node coor[28];
    int cnt=0;
    for(int i=0 ; i<=7 ; i++ )
    {
        for(int j=0 ; j<=7 ; j++)
        {
            int t=4*i+7*j;
            if(t<28)
            {
                coor[cnt].v=t;
                coor[cnt].n4=i;
                coor[cnt++].n7=j;
            }
        }
    }
    sort(coor,coor+cnt);
    //for(int i=0 ; i<cnt ; i++) printf("%d  ",coor[i].v);
    scanf("%d",&n);

    if(n>28)
    {
        int k=n/28;
        n=n%28;

        for(int i=0 ; i<cnt ; i++)
        {
            if(n==coor[i].v)
            {
                for(int j=0 ; j<coor[i].n4 ; j++)
                    printf("%d",4);
                for(int j=0 ; j<coor[i].n7 ; j++)
                    printf("%d",7);
                for(int i=0 ; i<k*4; i++)
                    printf("%d",7);
                puts("");
                return 0;
            }
        }
        puts("-1");
    }
    else if(n==28)
    {
        puts("7777");
    }
    else
    {
        if(n==0) puts("-1");
        else
        {
            for(int i=0 ; i<cnt ; i++)
            {
                if(n==coor[i].v)
                {
                    for(int j=0 ; j<coor[i].n4 ; j++)
                        printf("%d",4);
                    for(int j=0 ; j<coor[i].n7 ; j++)
                        printf("%d",7);
                    puts("");
                    return 0;
                }
            }
            puts("-1");
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int size=1000007;
int c4[size];
int c7[size];
int main()
{
    int n;
    cin>>n;
    if(n==4 || n==7)
    {
        cout<<n<<endl;
        return 0;
    }
    if(n%7==0){
        if(n%7==0)
        {
            n/=7;
            for(int i=0; i<n; i++)cout<<7;
            cout<<endl;
        }
        return 0;
    }
    int sum=0,k=0;
    while(sum<=n)
    {
        sum+=4;
        c4[k++]=sum;
    }
    int t=0;
    sum=0;
    while(sum<=n)
    {
        sum+=7;
        c7[t++]=sum;
    }
    bool ck=0;
    for(int i=0; i<k; i++)
    {
        for(int j=0; j<t; j++)
        {
            //cout<<c7[j]+c4[i]<<' ';
            if(c7[j]+c4[i]==n)
            {
                ck=1;
                for(int kk=0; kk<=i; kk++)cout<<4;
                for(int kk=0; kk<=j; kk++)cout<<7;
                break;
            }
        }
        if(ck)break;
    }
    if(!ck)
    {
        if(n%4==0)
        {
            n/=4;
            for(int i=0; i<n; i++)cout<<4;
            cout<<endl;
        }
        else  cout<<-1<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int size=1000007;
int c4[size];
int c7[size];
int main(){
    int n;
    cin>>n;
    if(n==4 || n==7){cout<<n<<endl;return 0;}
        int sum=0,k=0;
        while(sum<=n){
            sum+=4;
            c4[k++]=sum;
        }
        int t=0;
        sum=0;
        while(sum<=n){
            sum+=7;
            c7[t++]=sum;
        }
        bool ck=0;
        for(int i=0;i<k;i++){
            for(int j=0;j<t;j++){
                //cout<<c7[j]+c4[i]<<' ';
                if(c7[j]+c4[i]==n){
                    ck=1;
                    for(int kk=0;kk<=i;kk++)cout<<4;
                    for(int kk=0;kk<=j;kk++)cout<<7;
                    break;
                }
            }
            if(ck)break;
        }
        if(!ck)cout<<-1<<endl;

}


#include<bits/stdc++.h>
using namespace std;
const int size=1000007;
int c4[size];
int c7[size];
int main()
{
    int n;
    cin>>n;
    if(n==4 || n==7)
    {
        cout<<n<<endl;
        return 0;
    }
    int sum=0,k=0;
    while(sum<=n)
    {
        sum+=4;
        c4[k++]=sum;
    }
    int t=0;
    sum=0;
    while(sum<=n)
    {
        sum+=7;
        c7[t++]=sum;
    }
    bool ck=0;
    for(int i=0; i<k; i++)
    {
        for(int j=0; j<t; j++)
        {
            //cout<<c7[j]+c4[i]<<' ';
            if(c7[j]+c4[i]==n)
            {
                ck=1;
                for(int kk=0; kk<=i; kk++)cout<<4;
                for(int kk=0; kk<=j; kk++)cout<<7;
                break;
            }
        }
        if(ck)break;
    }
    if(!ck)
    {
        if(n%7==0)
        {
            n/=7;
            for(int i=0; i<n; i++)cout<<7;
            cout<<endl;
        }
        else if(n%4==0)
        {
            n/=4;
            for(int i=0; i<n; i++)cout<<4;
            cout<<endl;
        }
        else  cout<<-1<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int size=1000007;
int c4[size];
int c7[size];
int main(){
    int n;
    cin>>n;
        int sum=0,k=0;
        while(sum<=n){
            sum+=4;
            c4[k++]=sum;
        }
        int t=0;
        sum=0;
        while(sum<=n){
            sum+=7;
            c7[t++]=sum;
        }
        bool ck=0;
        for(int i=0;i<k;i++){
            for(int j=0;j<t;j++){
                //cout<<c7[j]+c4[i]<<' ';
                if(c7[j]+c4[i]==n){
                    ck=1;
                    for(int kk=0;kk<=i;kk++)cout<<4;
                    for(int kk=0;kk<=j;kk++)cout<<7;
                    break;
                }
            }
            if(ck)break;
        }
        if(!ck)cout<<-1<<endl;

}


#include<bits/stdc++.h>
using namespace std;
const int size=1000007;
int c4[size];
int c7[size];
int main(){
    int n;
    cin>>n;
    string ss="";
    vector<string>v;
    if(n%7==0){
        n/=7;
        for(int i=0;i<n;i++)cout<<7;
        cout<<endl;
    }
    else if(n%4==0){
        n/=4;
        for(int i=0;i<n;i++)cout<<4;
        cout<<endl;
    }
    else{
        int sum=0,k=0;
        while(sum<=n){
            sum+=4;
            c4[k++]=sum;
        }
        int t=0;
        sum=0;
        while(sum<=n){
            sum+=7;
            c7[t++]=sum;
        }
        bool ck=0;
        for(int i=0;i<k;i++){
            for(int j=0;j<t;j++){
                //cout<<c7[j]+c4[i]<<' ';
                if(c7[j]+c4[i]==n){
                    ck=1;
                    for(int kk=0;kk<=i;kk++)cout<<4;
                    for(int kk=0;kk<=j;kk++)cout<<7;
                    break;
                }
            }
            if(ck)break;
        }
        if(!ck)cout<<-1<<endl;
    }
}


#include <iostream>
#include <iomanip>

int main(int argc, char **argv)
{
    int n, X = 1e6, Y = 1e6;

    std::cin >> n;

    for(int y(0); y*7 <= n; ++y)
    {
        int x = (n - 7*y)/4;

        if(n != 4*x + 7*y)
            continue;

        if(x + y < X + Y || (x + y == X + Y && y < Y))
            X = x, Y = y;
    }

    if(X == 1e6 || n == 0)
        std::cout << "-1\n";
    else
    {
        std::cout.fill('4');
        std::cout << std::setw(X) << "";
        std::cout.fill('7');
        std::cout << std::setw(Y) << "" << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

char
     s[int(1e6) + 23] = "-1";
int
     min(1e7),
     mk(1e7),
     n;
int
main(int argn, char **args){// <-- Main
     std::scanf("%d", &n);

     for(int k(0), u(0), t; k <= n; k += 7, ++u)
          if(!(n - k & 0x3) && (t = u + (n - k >> 2)) < min)
	    min = t, mk = u;

     if(min != 1e7){
          std::memset(s, '4', min - mk);
          std::memset(s + min - mk, '7', mk);
          s[min] = 0;
     }

     std::printf("%s\n", s);

     return(0);
}


#include <bits/stdc++.h>

char
     s[int(1e5) + 23] = "-1";
int
     min(1e7),
     mk(1e7),
     n;
int
main(int argn, char **args){// <-- Main
     std::scanf("%d", &n);

     for(int k(0), u(0), t; k <= n; k += 7, ++u)
          if(!(n - k & 0x3) && (t = u + (n - k >> 2)) < min)
	    min = t, mk = u;

     if(min != 1e7){
          std::memset(s, '4', min - mk);
          std::memset(s + min - mk, '7', mk);
          s[min] = 0;
     }

     std::printf("%s\n", s);

     return(0);
}


#include <iostream>

using namespace std;

int luck(int h){

    if(h >= 0){
        if(h % 7 == 0)
            return h/7;
        else
            luck(h-4);
    }
    else
        return -1;
}

int main()
{
    int x;
    cin>>x;
/*    if(x%4 == 0)
    {
        for(int i = 0;i < x/4;i++)
            cout<<"4";
        return 0;
    }
    if(x%7 == 0)
    {
        for(int i = 0;i < x/7;i++)
            cout<<"7";
        return 0;
    }*/
    int d =luck(x);
    if(d == -1)
        cout<<"-1";
    else
    {
        for(int i = 0;i < d;i++)
            cout<<"4";
        x-= 4*d;
        for(int i = 0;i < x/7;i++)
            cout<<"7";
    }
    return 0;
}


#include <iostream>

using namespace std;

int luck(int h){

    if(h >= 0){
        if(h % 7 == 0)
            return h/7;
        else
            luck(h-4);
    }
    else
        return -1;
}

int main()
{
    int x;
    cin>>x;
    if(x%4 == 0)
    {
        for(int i = 0;i < x/4;i++)
            cout<<"4";
        return 0;
    }
    if(x%7 == 0)
    {
        for(int i = 0;i < x/7;i++)
            cout<<"7";
        return 0;
    }
    int d =luck(x);
    if(d == -1)
        cout<<"-1";
    else
    {
        for(int i = 0;i < d;i++)
            cout<<"7";
        x-= 7*d;
        for(int i = 0;i < x/4;i++)
            cout<<"4";
    }
    return 0;
}


#include <iostream>

using namespace std;

int luck(int h){

    if(h >= 0){
        if(h % 4 == 0)
            return h/4;
        else
            luck(h-7);
    }
    else
        return -1;
}

int main()
{
    int x;
    cin>>x;
    if(x%4 == 0)
    {
        for(int i = 0;i < x/4;i++)
            cout<<"4";
        return 0;
    }
    if(x%7 == 0)
    {
        for(int i = 0;i < x/7;i++)
            cout<<"7";
        return 0;
    }
    int d =luck(x);
    if(d == -1)
        cout<<"-1";
    else
    {
        for(int i = 0;i < d;i++)
            cout<<"4";
        x-= 4*d;
        for(int i = 0;i < x/7;i++)
            cout<<"7";
    }
    return 0;
}


#include <iostream>

using namespace std;

int luck(int h){

    if(h >= 0){
        if(h % 4 == 0)
            return h/4;
        else
            luck(h-7);
    }
    else
        return -1;
}
int luck2(int h){

    if(h >= 0){
        if(h % 7 == 0)
            return h/7;
        else
            luck2(h-4);
    }
    else
        return -1;
}
int main()
{
    int x;
    cin>>x;
    int d =luck2(x) , d2 = luck(x);
    if(d == -1 && d2 == -1)
        cout<<"-1";
    else
    {
        for(int i = 0;i < (x-(7*d))/4;i++)
            cout<<"4";
        for(int i = 0;i < d;i++)
            cout<<"7";
    }
    return 0;
}


#include <iostream>

using namespace std;

int luck(int h){

    if(h >= 0){
        if(h % 7 == 0)
            return h/7;
        else
            luck(h-4);
    }
    else
        return -1;
}

int main()
{
    int x;
    cin>>x;
    int d =luck(x);
    if(d == -1)
        cout<<"-1";
    else
    {
        for(int i = 0;i < d;i++)
            cout<<"7";
        x-= 7*d;
        for(int i = 0;i < x/4;i++)
            cout<<"4";
    }
    return 0;
}


#include <iostream>

using namespace std;

int luck(int h){

    if(h >= 0){
        if(h % 7 == 0)
            return h/7;
        else
            luck(h-4);
    }
    else
        return -1;
}

int main()
{
    int x;
    cin>>x;
    if(x%4 == 0)
    {
        for(int i = 0;i < x/4;i++)
            cout<<"4";
        return 0;
    }
    if(x%7 == 0)
    {
        for(int i = 0;i < x/7;i++)
            cout<<"7";
        return 0;
    }
    int d =luck(x);
    if(d == -1)
        cout<<"-1";
    else
    {
        for(int i = 0;i < d;i++)
            cout<<"4";
        x-= 4*d;
        for(int i = 0;i < x/7;i++)
            cout<<"7";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, s = 0, f = 0, temp = 0;
    scanf("%d", &n);
    while(n > 3)
    {
        if(n % 7 == 0)
        {
            s = n / 7;
            temp = 1;
            break;
        }
        n -= 4;
        f++;
        if(n == 0)
        {
            temp = 1;
        }
    }
    if(temp == 0)
    {
        printf("-1");
    }
    else
    {
        for(int i = 0 ; i < f ; i++)
        {
            printf("4");
        }
        for(int i = 0 ; i < s ; i++)
        {
            printf("7");
        }
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, s = 0, f = 0, temp = 0;
    scanf("%d", &n);
    while(n > 3)
    {
        n -= 4;
        f++;
        if(n % 7 == 0)
        {
            s = n / 7;
            temp = 1;
            break;
        }
    }
    if(temp == 0)
    {
        printf("-1");
    }
    else
    {
        for(int i = 0 ; i < f ; i++)
        {
            printf("4");
        }
        for(int i = 0 ; i < s ; i++)
        {
            printf("7");
        }
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, s = 0, f = 0, temp = 0;
    scanf("%d", &n);
    while(n > 3)
    {
        if(n % 7 == 0)
        {
            s = n / 7;
            temp = 1;
            break;
        }
        n -= 4;
        f++;
    }
    if(temp == 0)
    {
        printf("-1");
    }
    else
    {
        for(int i = 0 ; i < f ; i++)
        {
            printf("4");
        }
        for(int i = 0 ; i < s ; i++)
        {
            printf("7");
        }
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, s = 0, f = 0, temp = 0;
    scanf("%d", &n);
    while(n > 3)
    {
        n -= 7;
        s++;
        if(n % 4 == 0)
        {
            f = n / 4;
            temp = 1;
            break;
        }
    }
    if(temp == 0)
    {
        printf("-1");
    }
    else
    {
        for(int i = 0 ; i < f ; i++)
        {
            printf("4");
        }
        for(int i = 0 ; i < s ; i++)
        {
            printf("7");
        }
    }
    printf("\n");
    return 0;
}


/****************************************************************************\
                       Belief yourself,Respect yourself                       |
                                                                              |
        /\           /--------|   |--------|  |--------|    ----       ----   |
       /  \         /             |           |             | \         / |   |
      /    \       |              |           |             |  \       /  |   |
     /      \      |----|         |--------|  |--------|    |   \     /   |   |
    /--------\          |------|  |           |             |    -----    |   |
   /          \                |  |           |             |             |   |
  /            \               /  |           |             |             |   |
----          ---- |----------/   |--------|  |--------|  ----          ----  |
                                                                              |
*****************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i,intial,n) for(int i=intial; i<(n) ; i++)
#define REP(i,intial,n) for(int i=intial; i<=(n) ; i++)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define MP make_pair
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007

//Bit Operation
bool checkBit(LL n, int i) { return n&(1LL<<i); }  //AND
LL setBit(LL n, int i) { return n|(1LL<<i);; }     //OR
LL resetBit(LL n, int i) { return n&(~(1LL<<i)); } //OFF

template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

LL big_mod(LL n, LL p)
{
    if(p==0) return 1;
    if(!(p&1))
    {
        LL r = big_mod(n,p/2) % MOD;
        return ( (r%MOD) * (r%MOD) ) % MOD;
    }
    else return ( ( n%MOD) * (big_mod(n,p-1) %MOD)) % MOD;
}

long long gcd(long long a, long long b) {
  while (b != 0) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n;
    while(cin>>n)
    {
        int b=0;
        int flag=0;
        int a;
        int minimum=INT_MAX;
        int aa,bb;
        while(true)
        {
            a=(n-(b*7))/4;
            //if((a*4+b*7)==n && a>=0)
            //{
                //flag=1;
                //break;
            //}
            if((a*4+b*7)==n && a>=0)
            {
            if(minimum>(a+b))
            {
                minimum=a+b;
                aa=a;
                bb=b;
                flag=1;
            }
            }
            if((a*4+b*7)>n) break;
            b++;
        }
        if(flag)
        {
        for(int i=1;i<=aa;i++) cout<<"4";
        for(int i=1;i<=bb;i++) cout<<"7";
        cout<<endl;
        }
        else cout<<"-1"<<endl;
    }

}


/****************************************************************************\
                       Belief yourself,Respect yourself                       |
                                                                              |
        /\           /--------|   |--------|  |--------|    ----       ----   |
       /  \         /             |           |             | \         / |   |
      /    \       |              |           |             |  \       /  |   |
     /      \      |----|         |--------|  |--------|    |   \     /   |   |
    /--------\          |------|  |           |             |    -----    |   |
   /          \                |  |           |             |             |   |
  /            \               /  |           |             |             |   |
----          ---- |----------/   |--------|  |--------|  ----          ----  |
                                                                              |
*****************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i,intial,n) for(int i=intial; i<(n) ; i++)
#define REP(i,intial,n) for(int i=intial; i<=(n) ; i++)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define MP make_pair
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007

//Bit Operation
bool checkBit(LL n, int i) { return n&(1LL<<i); }  //AND
LL setBit(LL n, int i) { return n|(1LL<<i);; }     //OR
LL resetBit(LL n, int i) { return n&(~(1LL<<i)); } //OFF

template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

LL big_mod(LL n, LL p)
{
    if(p==0) return 1;
    if(!(p&1))
    {
        LL r = big_mod(n,p/2) % MOD;
        return ( (r%MOD) * (r%MOD) ) % MOD;
    }
    else return ( ( n%MOD) * (big_mod(n,p-1) %MOD)) % MOD;
}

long long gcd(long long a, long long b) {
  while (b != 0) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n;
    while(cin>>n)
    {
        int b=0;
        int flag=0;
        int a;
        while(true)
        {
            a=(n-(b*7))/4;
            if((a*4+b*7)==n && a>=0)
            {
                flag=1;
                break;
            }
            if((a*4+b*7)>n) break;
            b++;
        }
        if(flag)
        {
        for(int i=1;i<=a;i++) cout<<"4";
        for(int i=1;i<=b;i++) cout<<"7";
        cout<<endl;
        }
        else cout<<"-1"<<endl;
    }

}


#include <bits/stdc++.h>
using namespace std;
long long n,s,f=-1,i,j;
int main()
{
    cin >> n;
    s=n/7;
    for(i=s;i>=0;i--)
    {
        if((n-i*7)%4==0)
        {
            f=(n-i*7)/4;
            j=i;
            break;
        }
    }
    if(f==-1)
    {
        cout << -1;
    }
    else
    {
        for(i=1;i<=f;i++)
        {
            cout << 4;
        }
        for(i=1;i<=j;i++)
        {
            cout << 7;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,s,f=-1,i;
int main()
{
    cin >> n;
    s=n/7;
    for(i=s;i>=0;i--)
    {
        if((n-i*7)%4==0)
        {
            f=(n-i*7)/4;
            break;
        }
    }
    if(f==-1)
    {
        cout << -1;
    }
    else
    {
        for(i=1;i<=f;i++)
        {
            cout << 4;
        }
        for(i=1;i<=s;i++)
        {
            cout << 7;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,s,f=-1,i;
int main()
{
    cin >> n;
    s=n/7;
    for(i=s;i>=0;i--)
    {
        if((n-s*7)%4==0)
        {
            f=(n-s*7)/4;
        }
    }
    if(f==-1)
    {
        cout << -1;
    }
    else
    {
        for(i=1;i<=f;i++)
        {
            cout << 4;
        }
        for(i=1;i<=s;i++)
        {
            cout << 7;
        }
    }
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>v;
	while(n>0)
	{
		if(n%4==0 && n%7==0)
		{
			n=n-4;
		v.push_back(4);

		}
		if(n%7==0)
		{
			n=n-7;
			v.push_back(7);
		}
		else{
		n=n-4;
		v.push_back(4);
	}
	}
	if(n==0)
	{
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i];
	}
}
else{
	cout<<-1;
}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>v;
	while(n>0)
	{
		if(n%7==0)
		{
			n=n-7;
			v.push_back(7);
		}
		else{
		n=n-4;
		v.push_back(4);
	}
	}
	if(n==0)
	{
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i];
	}
}
else{
	cout<<-1;
}
	cout<<endl;
	return 0;
}


#include <iostream>

using namespace std;
int n;
int main()
{
    int x=0,y=0,s=0,aux,i;
    cin>>n;
    aux=n;
    if(aux%7==0)
    {
        for(i=1; i<=aux/7; i++)
            cout<<"7";
        return 0;
    }
    while(n>0)
    {
        s++;
        n-=4;
        if(n%7==0 && n>0)
        {
            x=s;
            y=n/7;
            break;
        }
    }
    if(x && y)
    {
        for(i=1; i<=x; i++)
            cout<<"4";
        for(i=1; i<=y; i++)
            cout<<"7";
    }
    else if(!x && !y)
    {
        if(aux%4==0)
            for(i=1; i<=aux/4; i++)
                cout<<"4";
        else cout<<"-1\n";
    }
    return 0;
}


#include <iostream>

using namespace std;
int n;
int main()
{
    int x=0,y=0,s=0,aux,i;
    cin>>n;
    aux=n;
    while(n>0)
    {
        s++;
        n-=4;
        if(n%7==0)
        {
            x=s;
            y=n/7;
        }
    }
    if(x && y)
    {
        for(i=1;i<=x;i++)
            cout<<"4";
        for(i=1;i<=y;i++)
            cout<<"7";
    }
    else if(!x && !y)
    {
        if(aux%7==0)
            for(i=1;i<=aux/7;i++)
                    cout<<"7";
        else if(aux%4==0)
            for(i=1;i<=aux/4;i++)
                cout<<"4";
        else cout<<"-1\n";
    }
    return 0;
}


#include <iostream>

using namespace std;
int n;
int main()
{
    int x=0,y=0,s=0,aux,i;
    cin>>n;
    aux=n;
    while(n>0)
    {
        s++;
        n-=4;
        if(n%7==0 && n>0)
        {
            x=s;
            y=n/7;
            break;
        }
    }
    if(x && y)
    {
        for(i=1;i<=x;i++)
            cout<<"4";
        for(i=1;i<=y;i++)
            cout<<"7";
    }
    else if(!x && !y)
    {
        if(aux%7==0)
            for(i=1;i<=aux/7;i++)
                    cout<<"7";
        else if(aux%4==0)
            for(i=1;i<=aux/4;i++)
                cout<<"4";
        else cout<<"-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
    ll n,ok=0,s=0,f=0;
    cin>>n;
    ll val=((n+4-1)/4);
    vector<char>arr;
    for(int i=0; i<val; i++)
    {
        arr.push_back('4');
    }
    ll tot=val*4;
    ll i=arr.size()-1;
    while(1)
    {
        if(tot>n)
        {

            if(arr.back()=='4')
            {
                tot-=4;
                arr.pop_back();
                tot+=7;
                arr.push_back('7');
            }
            if(arr.back()=='7')
            {
                tot-=11;
                arr.pop_back();
                arr.pop_back();
                tot+=7;
                arr.push_back('7');
            }

           // cout<<arr[i];

        }
        if(tot==n)break;
        if(tot<n)
        {
            ok=1;
            break;
        }
    }
    for(int i=0;i<arr.size();i++){
        if(arr[i]=='7')s=1;
        if(arr[i]=='4')f=1;
        if(f==1&&s==1)break;
    }
    if(ok==1||s==0||f==0)
    {
        cout<<"-1"<<endl;
        return 0;
    }

    for(int i=0; i<arr.size(); i++)
    {
        cout<<arr[i];
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
    ll n,ok=0,s=0,f=0,sum=0,u=1;
    cin>>n;
    ll val=((n+7-1)/7);
    ll val2=((n+4-1)/4);
    ll tot1=val2*4;
    vector<char>arr;
    vector<char>arr1;
    if(tot1==n)
    {
        for(int i=0; i<val2; i++)
        {
            arr1.push_back('4');
        }
    }
    for(int i=0; i<val; i++)
    {
        arr.push_back('7');
    }
    ll tot=val*7;
    ll i=arr.size()-1;
    if(tot==n)u=0;
    while(u)
    {
        tot-=7;
        tot+=4;
        arr[i]='4';
        i--;
        if(tot==n)break;
        if(i==-1)
        {
            u=0;
        }
    }
    sort(arr.begin(),arr.end());
    for(int i=0; i<arr.size(); i++)sum+=arr[i]-'0';
    if(sum==n&&tot1==n)
    {

        if(arr1.size()>arr.size())
        {
            for(int i=0; i<arr.size(); i++)
            {
                cout<<arr[i];
            }
        }
        else
        {
            for(int i=0; i<arr1.size(); i++)
            {
                cout<<arr1[i];
            }
        }
        return 0;
    }
    if(tot1==n){
        for(int i=0;i<arr1.size();i++)cout<<arr1[i];
        return 0;
    }
    if(sum==n)ok=0;
    else ok=1;
    if(ok==1)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    for(int i=0; i<arr.size(); i++)
    {
        cout<<arr[i];
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
    ll n,ok=0,s=0,f=0,sum=0,u=1;
    cin>>n;
    ll val=((n+7-1)/7);
    ll val2=((n+4-1)/4);
    ll tot1=val2*4;
    vector<char>arr;
    vector<char>arr1;
    if(tot1==n)
    {
        for(int i=0; i<val2; i++)
        {
            arr1.push_back('4');
        }
    }
    for(int i=0; i<val; i++)
    {
        arr.push_back('7');
    }
    ll tot=val*7;
    ll i=arr.size()-1;
    if(tot==n)u=0;
    while(u)
    {
        tot-=7;
        tot+=4;
        arr[i]='4';
        i--;
        if(tot==n)break;
        if(i==-1)
        {
            u=0;
        }
    }
    sort(arr.begin(),arr.end());
    for(int i=0; i<arr.size(); i++)sum+=arr[i]-'0';
    if(sum==n)ok=0;
    else ok=1;
    if(tot1==n||sum==n)
    {

        if(arr1.size()>arr.size()||tot==n)
        {
            for(int i=0; i<arr.size(); i++)
            {
                cout<<arr[i];
            }
        }
        else
        {
            for(int i=0; i<arr1.size(); i++)
            {
                cout<<arr1[i];
            }
        }
        return 0;
    }
    if(ok==1)
    {
        cout<<"-1"<<endl;
        return 0;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
    ll n,ok=0,s=0,f=0,sum=0;
    cin>>n;
    ll val=((n+7-1)/7);
    vector<char>arr;
    for(int i=0; i<val; i++)
    {
        arr.push_back('7');
    }
    ll tot=val*7;
    ll i=arr.size()-1;
    while(i)
    {
       tot-=7;
       tot+=4;
       arr[i]='4';
       i--;
       if(tot==n)break;
    }
    sort(arr.begin(),arr.end());
    for(int i=0;i<arr.size();i++){
        if(arr[i]=='7')s=1;
        if(arr[i]=='4')f=1;
        if(f==1&&s==1)break;
    }
    for(int i=0;i<arr.size();i++)sum+=arr[i]-'0';
    if(sum==n)ok=0;
    else ok=1;
    if(ok==1||s==0||f==0)
    {
        cout<<"-1"<<endl;
        return 0;
    }

    for(int i=0; i<arr.size(); i++)
    {
        cout<<arr[i];
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;

int main()
{
    ll n,s=0,f=0,tot=0,ok=0;
    cin>>n;
    tot=n;
    while(tot)
    {
        if(tot%7==0)
        {
            ok=1;
            break;
        }
        tot-=4;
        f++;
        if(tot<0)
        {
            ok=0;
            break;
        }
    }
    s=tot/7;
    if(tot==0)ok=1;
    if(ok==0)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    for(int i=0; i<f; i++)cout<<"4";
    for(int i=0; i<s; i++)cout<<"7";
    return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
    ll n,ok=0,s=0,f=0,sum=0,u=1;
    cin>>n;
    ll val=((n+7-1)/7);
    ll val2=((n+4-1)/4);
    ll tot1=val2*4;
    vector<char>arr;
    if(tot1==n)
    {
        for(int i=0; i<val2; i++)
        {
            arr.push_back('4');
        }
        for(int i=0; i<arr.size(); i++)
        {
            cout<<arr[i];
        }
        return 0;
    }
    for(int i=0; i<val; i++)
    {
        arr.push_back('7');
    }
    ll tot=val*7;
    ll i=arr.size()-1;
    if(tot==n)u=0;
    while(u)
    {
        tot-=7;
        tot+=4;
        arr[i]='4';
        i--;
        if(tot==n)break;
        if(i==-1)
        {
            u=0;
        }
    }
    sort(arr.begin(),arr.end());
    for(int i=0; i<arr.size(); i++)sum+=arr[i]-'0';
    if(sum==n)ok=0;
    else ok=1;
    if(ok==1)
    {
        cout<<"-1"<<endl;
        return 0;
    }

    for(int i=0; i<arr.size(); i++)
    {
        cout<<arr[i];
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,mn="";
int main()
{
  int n;
  cin>>n;
  if(n%7==0)
  {
  for(int i=0;i<n/7;i++)
    cout<<"7";
  return 0;
  }
  for(int i=0;i<=n/4;i++)
    for(int j=0;j<=(n-i*4)/7;j++)
    {
    	if((i*4+j*7)==n)
    	{
    	  s="";
    	  for(int k=0;k<i;k++)
    	    s+='4';
    	  for(int k=0;k<j;k++)
    	    s+='7';
    	  if(mn=="")
    	    mn=s;
    	  else
    	  {
    	  	if(s.size()<=mn.size())
    	  	  mn=s;
    	  	else
    	  	  mn=min(mn,s);
		  }
		}
	}
	if(mn==" ")
	  cout<<-1;
	else
	  cout<<mn<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,mn="";
int main()
{
  int n;
  cin>>n;
  if(n%7==0)
  {
  for(int i=0;i<n/7;i++)
    cout<<"7";
  return 0;
  }
  for(int i=0;i<=n/4;i++)
    for(int j=0;j<=(n-i*4)/7;j++)
    {
    	if((i*4+j*7)==n)
    	{
    	  s="";
    	  for(int k=0;k<i;k++)
    	    s+='4';
    	  for(int k=0;k<j;k++)
    	    s+='7';
    	  if(mn=="")
    	    mn=s;
    	  else
    	  {
    	  	if(s.size()<mn.size())
    	  	  mn=s;
    	  	else
    	  	  if(s.size()==mn.size())
    	  	    mn=min(mn,s);
		  }
		}
	}
	if(mn=="")
	  cout<<-1;
	else
	  cout<<mn<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s,mn="";
int main()
{
  int n;
  cin>>n;
  if(n%7==0)
  {
  for(int i=0;i<n/7;i++)
    cout<<"7";
  return 0;
  }
  for(int i=0;i<=6;i++)
    for(int j=0;j<=(n-i*4)/7;j++)
    {
    	if((i*4+j*7)==n)
    	{
    	  s="";
    	  for(int k=0;k<i;k++)
    	    s+='4';
    	  for(int k=0;k<j;k++)
    	    s+='7';
    	  if(mn=="")
    	    mn=s;
    	  else
    	  {
    	  	if(s.size()<mn.size())
    	  	  mn=s;
    	  	else
    	  	  if(s.size()==mn.size())
    	  	    mn=min(mn,s);
		  }
		}
	}
	if(mn=="")
	  cout<<-1;
	else
	  cout<<mn<<" ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string k;
    int n;cin>>n;
    while(n>0)
    {
        if(n%7==0)
        {
            k.push_back('7');
            n-=7;
        }
        else
        {
            k.push_back('4');
            n-=4;
        }
    }
    if(n<0)
    cout<<-1;
    else
    cout<<k;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n,i;
    string s;
    for(cin>>n;n%7!=0;s+='4')
    {
        n-=4;
        if(n<0){cout<<-1; return 0;}
    }
    cout<<s;
    for(i=n/7;i--;cout<<7);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
long long n;
cin>>n;
long long m;
if(n%4==0){
    m=n/4;
    for(long long i=0;i<m;i++)
        cout<<4;
    cout<<'\n';
}

else if(n%7==0){
    m=n/7;
    for(long long i=0;i<m;i++)
        cout<<7;
    cout<<'\n';
}
else if((n-14)%4==0){
    n=n-14;
    long long m=n/4;
        for (long long i=0;i<m;i++)
            cout<<4;
        cout<<7<<7;
        cout<<'\n';

}
else if((n-21)%4==0){
         n=n-21;
    long long m=n/4;
        for (long long i=0;i<m;i++)
            cout<<4;
        cout<<7<<7<<7;
        cout<<'\n';

}
else if((n-4)%7==0){
            n=n-4;
    long long m=n/7;
           cout<<4;
        for (long long i=0;i<m;i++)
            cout<<7;

        cout<<'\n';

}

else if((n-8)%7==0){
        n=n-8;
    long long m=n/7;
           cout<<4<<4;
        for (long long i=0;i<m;i++)
            cout<<7;

        cout<<'\n';

}
else if((n-12)%7==0){
        n=n-12;
    long long m=n/7;
           cout<<4<<4<<4;
        for (long long i=0;i<m;i++)
            cout<<7;

        cout<<'\n';

}
else if((n-16)%7==0){
        n=n-16;
    long long m=n/7;
           cout<<4<<4<<4<<4;
        for (long long i=0;i<m;i++)
            cout<<7;

        cout<<'\n';

}
else if((n-20)%7==0){
        n=n-20;
    long long m=n/7;
           cout<<4<<4<<4<<4<<4;
        for (long long i=0;i<m;i++)
            cout<<7;

        cout<<'\n';

}
else if((n-24)%7==0){
        n=n-24;
    long long m=n/7;
           cout<<4<<4<<4<<4<<4<<4;
        for (long long i=0;i<m;i++)
            cout<<7;

        cout<<'\n';

}
else{

       n=n-7;
       if(n%4==0){
        long long m=n/4;
        for (long long i=0;i<m;i++)
            cout<<4;
        cout<<7;
        cout<<'\n';
       }
       else{
        cout<<-1<<'\n';
       }
}
return 0;
}


#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	int x=0;
	int y=0;
	int f=1;
	int z=n/7;
	z=z*7;
	while(true)
	{
		if(z<4)
		 {
		 	f=0;
		 	break;
		 }
		if((n-z)%4==0)
		{
			break;
		}
		z-=7;

	}
	 if(f)
	 {
	 	x=(n-z)/4;
	 	y=z/7;
	 	int i;
	 	for(i=1;i<=x;i++)
	 	{
	 		printf("4");
		 }
		 for(i=1;i<=y;i++)
		 {
		 	printf("7");
		 }
		 cout<<endl;
	 }
	 else
	 {
	 	if(n%4==0)
	 	{
	 		x=n/4;
	 		int i=0;
	 		for(;i<x;i++)
	 		printf("4");

		 }
		 else
	 	printf("-1\n");
	 }
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;

int a[1001000];

int main()
{
    int n;
    cin>>n;
    int k=0;
    while(n%7&&n>0){
        a[k++]=4;
        n-=4;
    }
    if(n<0) cout<<-1<<endl;
    else{
        for(int i=0;i<n/7;i++){
            a[k++]=7;
        }
        for(int i=0;i<k;i++) cout<<a[i];
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[1001000];

int main()
{
    int n;
    cin>>n;
    int k=0;
    while(n%4&&n>0){
        a[k++]=7;
        n-=7;
    }
    if(n<0) cout<<-1<<endl;
    else{
        for(int i=0;i<n/4;i++){
            a[k++]=4;
        }
        for(int i=k-1;i>=0;i--) cout<<a[i];
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (int x) {  return x && (!(x&(x-1)));  }
void solve()
{
    ll n; cin>>n;
    ll a,b=1e9,sum=1e9;
    rep(i,0,n)
    {
        if(n-7*i>=0 and (n-7*i)%4==0)
        {
            if(sum>(i+(n-7*i)/4))
            {
                a=(n-7*i)/4;
                b=i;
                sum=a+b;
            }
            else if(sum==a+b and b>i)
            {
                a=(n-7*i)/4;
                b=i;
            }
        }
    }
    if(sum==1e9) { cout<<"-1"; return;  }
    rep(i,0,a) cout<<"4";
    rep(i,0,b) cout<<"7";
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (int x) {  return x && (!(x&(x-1)));  }
map<ll,ll> mp;
ll sum(ll n)
{
    ll s=0;
    while(n)
    {
        s+=(n%10);
        n/=10;
    }return s;
}
void make_digit(ll n)
{
    if(n>1e6) return;
    ll s=sum(n);
    if(mp.find(s)!=mp.end()) mp[s]=min(mp[s],n);
    else mp[s]=n;
    make_digit(n*10+4);
    make_digit(n*10+7);
}
void solve()
{
    ll n; cin>>n;
    make_digit(0);
    if(mp.find(n)!=mp.end()) cout<<mp[n];
    else cout<<"-1";

}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf INFINITY
#define mod 1000000007

using namespace std;
const int MAX = 1e6 + 10;
const int MIN = 5e3 + 10;

long long shit[MAX], dp[MAX];
const int MAXN = INT_MAX;
vector < pair <int, int> > v;

void bt (int n, int x, int y) {
	if (n == 0) v.pb(mp(x, y));
	if (n - 4 >= 0)
		bt (n - 4, x + 1, y);
	if (n - 7 >= 0)
		bt (n - 7, x, y + 1);
}

int main ()
{
	int n;
	cin >> n;
	bt(n, 0, 0);
	if (!v.size()) {
		cout << -1 << endl;
		return 0;
	}
	int ans = MAXN, pos = -1;
	n = v.size();
	for (int i = 0; i < n; i++) {
		int l = v[i].first, r = v[i].second;
		if (l + r < ans){
			ans = l + r;
			pos = i;
		}
	}
	for (int i = 0; i < n ; i++){
		int l = v[i].first, r = v[i].second;
		if (i == pos) {
			for (int j = 0; j < l; j++)
				cout << '4';
			for (int j = 0; j < r; j++)
				cout << '7';
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf INFINITY
#define mod 1000000007

using namespace std;
const int MAX = 1e6 + 10;
const int MIN = 5e3 + 10;

long long dp[MAX];
bool vis[MAX];
int shit;
const int MAXN = INT_MAX;
vector < pair <int, int> > v;

void bt (int n, int x, int y) {
	vis[n] = true;
	if (n > shit) return ;
	if (n == shit)
		v.pb(mp(x, y));
	if (!vis[n + 4])
		bt(n + 4, x + 1, y);
	if (!vis[n + 7])
		bt(n + 7, x, y + 1);
}

int main ()
{
	int n;
	cin >> n;
	shit = n;
	bt(0, 0, 0);
	if (!v.size()) {
		cout << -1 << endl;
		return 0;
	}
	int ans = MAXN, pos = -1;
	n = v.size();
	for (int i = 0; i < n; i++) {
		int l = v[i].first, r = v[i].second;
		if (l + r < ans){
			ans = l + r;
			pos = i;
		}
	}
	for (int i = 0; i < n ; i++){
		int l = v[i].first, r = v[i].second;
		if (i == pos) {
			for (int j = 0; j < l; j++)
				cout << '4';
			for (int j = 0; j < r; j++)
				cout << '7';
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf INFINITY
#define mod 1000000007

using namespace std;
const int MAX = 1e6 + 10;
const int MIN = 5e3 + 10;

long long shit[MAX], dp[MAX];
const int MAXN = INT_MAX;
vector < pair <int, int> > v;

void bt (int n, int x, int y) {
	if (n == 0) {v.pb(mp(x, y));
	return ;}
	if (n - 4 >= 0)
		bt (n - 4, x + 1, y);
	if (n - 7 >= 0)
		bt (n - 7, x, y + 1);
}

int main ()
{
	int n;
	cin >> n;
	bt(n, 0, 0);
	if (!v.size()) {
		cout << -1 << endl;
		return 0;
	}
	int ans = MAXN, pos = -1;
	n = v.size();
	for (int i = 0; i < n; i++) {
		int l = v[i].first, r = v[i].second;
		if (l + r < ans){
			ans = l + r;
			pos = i;
		}
	}
	for (int i = 0; i < n ; i++){
		int l = v[i].first, r = v[i].second;
		if (i == pos) {
			for (int j = 0; j < l; j++)
				cout << '4';
			for (int j = 0; j < r; j++)
				cout << '7';
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf INFINITY
#define mod 1000000007

using namespace std;
const int MAX = 1e6 + 10;
const int MIN = 5e3 + 10;

long long shit[MAX], dp[MAX];
bool vis[MAX];
const int MAXN = INT_MAX;
vector < pair <int, int> > v;

void bt (int n, int x, int y) {
	vis[n] = true;
	if (n == 0) {
		v.pb(mp(x, y));
		return ;
	}
	if (n - 4 >= 0 && !vis[n - 4])
		bt (n - 4, x + 1, y);
	if (n - 7 >= 0 && !vis[n - 7])
		bt (n - 7, x, y + 1);
}

int main ()
{
	int n;
	cin >> n;
	bt(n, 0, 0);
	if (!v.size()) {
		cout << -1 << endl;
		return 0;
	}
	int ans = MAXN, pos = -1;
	n = v.size();
	for (int i = 0; i < n; i++) {
		int l = v[i].first, r = v[i].second;
		if (l + r < ans){
			ans = l + r;
			pos = i;
		}
	}
	for (int i = 0; i < n ; i++){
		int l = v[i].first, r = v[i].second;
		if (i == pos) {
			for (int j = 0; j < l; j++)
				cout << '4';
			for (int j = 0; j < r; j++)
				cout << '7';
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin >> n;
	if (n < 4){
		cout << "-1";
		return 0;
	}
	int bullshit = n / 7;
	int rem = n % 7;
	int fuck = rem / 4;
	int shit = rem % 4;
	if (shit != 0) {
		if (bullshit >= shit){
			fuck += ((7 * shit)+shit) / 4;
			bullshit -= shit;
		}
		else{
			cout<<"-1";
			return 0;
		}
	}
	for (int i = 0; i < fuck; i++)
		cout<<"4";
	for (int i = 0; i < bullshit; i++)
		cout<<"7";
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf INFINITY
#define mod 1000000007

using namespace std;
const int MAX = 1e6 + 10;
const int MIN = 5e3 + 10;

long long shit[MAX], dp[MAX];
bool vis[MAX];
const int MAXN = INT_MAX;
vector < pair <int, int> > v;

void bt (int n, int x, int y) {
	vis[n] = true;
	if (n == 0) {
		v.pb(mp(x, y));
	}
	if (n - 4 >= 0 && !vis[n - 4])
		bt (n - 4, x + 1, y);
	if (n - 7 >= 0 && !vis[n - 7])
		bt (n - 7, x, y + 1);
}

int main ()
{
	int n;
	cin >> n;
	bt(n, 0, 0);
	if (!v.size()) {
		cout << -1 << endl;
		return 0;
	}
	int ans = MAXN, pos = -1;
	n = v.size();
	for (int i = 0; i < n; i++) {
		int l = v[i].first, r = v[i].second;
		if (l + r < ans){
			ans = l + r;
			pos = i;
		}
	}
	for (int i = 0; i < n ; i++){
		int l = v[i].first, r = v[i].second;
		if (i == pos) {
			for (int j = 0; j < l; j++)
				cout << '4';
			for (int j = 0; j < r; j++)
				cout << '7';
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf INFINITY
#define mod 1000000007

using namespace std;
const int MAX = 1e6 + 10;
const int MIN = 5e3 + 10;

long long dp[MAX];
bool vis[MAX];
int shit;
const int MAXN = INT_MAX;
vector < pair <int, int> > v;

void bt (int n, int x, int y) {
	if (n > shit) return ;
	if (n == shit)
		v.pb(mp(x, y));
	if (!vis[n + 4])
		bt(n + 4, x + 1, y);
	if (!vis[n + 7])
		bt(n + 7, x, y + 1);
}

int main ()
{
	int n;
	cin >> n;
	shit = n;
	bt(0, 0, 0);
	if (!v.size()) {
		cout << -1 << endl;
		return 0;
	}
	int ans = MAXN, pos = -1;
	n = v.size();
	for (int i = 0; i < n; i++) {
		int l = v[i].first, r = v[i].second;
		if (l + r < ans){
			ans = l + r;
			pos = i;
		}
	}
	for (int i = 0; i < n ; i++){
		int l = v[i].first, r = v[i].second;
		if (i == pos) {
			for (int j = 0; j < l; j++)
				cout << '4';
			for (int j = 0; j < r; j++)
				cout << '7';
			return 0;
		}
	}
	return 0;
}


/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

using namespace std;
const int maxn = 1000*100 ;
int main()
{
int n ; cin>>n ;
vec<int> ans ;
int i = 0  ;
int f = n/4 , s = 0;
 bool b = true ;
for(   i = 0 ; i < n/4 + 1;i++)
{
	/*
	if(n - (s*7) == 4)
	{

	}
	if(n - (i*4) == 3)
	{
		i-- ;
		s++;
		 break ;
	}*/
	int x = n - i*4 ;
	if(x % 7 == 0 )
	{
		while(i--) cout<<4;
		for(i = 0 ; i < x/7 ; i++) cout<<7 ;
		b = false ;
		break ;
	 }

	//i-- ;
	s++ ;
	//if(n - (i*4 + s*7) > 3) i++ ;

}

/*for( ; i >= 1  ; i--)
{
	cout<<"4";
	}
	while(s--)
	cout<<7 ;
*/
if(b) cout<<-1;
}
//////
////////
///////////


/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

using namespace std;
const int maxn = 1000*100 ;
int main()
{
int n ; cin>>n ;
vec<int> ans ;
int i = 0  ;
int f = n/4 , s = 0;
 bool b = true ;
for(   i = 0 ; i < n/4 ;i++)
{
	/*
	if(n - (s*7) == 4)
	{

	}
	if(n - (i*4) == 3)
	{
		i-- ;
		s++;
		 break ;
	}*/
	int x = n - i*4 ;
	if(x % 7 == 0 )
	{
		while(i--) cout<<4;
		for(i = 0 ; i < n/7 ; i++) cout<<7 ;
		b = false ;
		break ;
	 }

	//i-- ;
	s++ ;
	//if(n - (i*4 + s*7) > 3) i++ ;

}

/*for( ; i >= 1  ; i--)
{
	cout<<"4";
	}
	while(s--)
	cout<<7 ;
*/
if(b) cout<<-1;
}
//////
////////
///////////


/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

using namespace std;
const int maxn = 1000*100 ;
int main()
{
int n ; cin>>n ;
vec<int> ans ;
int i = 0  ;
int f = n/4 , s = 0;
 bool b = true ;
for(   i = 0 ; i < n/4 ;i++)
{
	/*
	if(n - (s*7) == 4)
	{

	}
	if(n - (i*4) == 3)
	{
		i-- ;
		s++;
		 break ;
	}*/
	int x = n - i*4 ;
	if(x % 7 == 0 )
	{
		while(i--) cout<<4;
		for(i = 0 ; i < x/7 ; i++) cout<<7 ;
		b = false ;
		break ;
	 }

	//i-- ;
	s++ ;
	//if(n - (i*4 + s*7) > 3) i++ ;

}

/*for( ; i >= 1  ; i--)
{
	cout<<"4";
	}
	while(s--)
	cout<<7 ;
*/
if(b) cout<<-1;
}
//////
////////
///////////


#include <bits/stdc++.h>
using namespace std;

const int INF = 123456789;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a = INF, b = INF;
    cin >> n;
    for (int i = 0; i * 4 <= n; i++) {
        int x = n - i * 4;
        if (x % 7 == 0) {
            if (i + x / 7 < a + b) {
                a = i; b = x / 7;
            } else if (i + x / 7 == a + b) {
                if (i < a) {
                    a = i;
                    b = x / 7;
                }
            }
        }
    }
    if (a == INF && b == INF) cout << -1;
    else {
        for (int i = 0; i < a; i++) cout << '4';
        for (int i = 0; i < b; i++) cout << '7';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int INF = 123456789;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a = INF, b = INF;
    cin >> n;
    for (int i = 0; i * 4 <= n; i++) {
        int x = n - i * 4;
        if (x % 7 == 0) {
            if (i + x / 7 < a + b) {
                a = i; b = x / 7;
            } else if (i + x / 7 == a + b) {
                if (i < a) {
                    a = i;
                    b = x / 7;
                }
            }
        }
    }
    if (a == 100 && b == 100) cout << -1;
    else {
        for (int i = 0; i < a; i++) cout << '4';
        for (int i = 0; i < b; i++) cout << '7';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a = 100, b = 100;
    cin >> n;
    for (int i = 0; i * 4 <= n; i++) {
        int x = n - i * 4;
        if (x % 7 == 0) {
            if (i + x / 7 < a + b) {
                a = i; b = x / 7;
            } else if (i + x / 7 == a + b) {
                if (i < a) {
                    a = i;
                    b = x / 7;
                }
            }
        }
    }
    if (a == 100 && b == 100) cout << -1;
    else {
        for (int i = 0; i < a; i++) cout << '4';
        for (int i = 0; i < b; i++) cout << '7';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for(int i = n / 7; i >= 0; --i)
    {
        if((n - (i * 7)) % 4 == 0) cout << string((n - (i * 7)) / 4, '4') << string(i, '7') << endl, exit(0);
    }
    cout << -1 << endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for(int i = n / 4; i >= 0; --i)
    {
        if((n - (i * 4)) % 7 == 0) cout << string(i, '4') << string((n - (i * 4)) / 7, '7') << endl, exit(0);
    }
    cout << -1 << endl;
}


#include<bits/stdc++.h>
using namespace std;

int a[4];

int main()
{
    for(int i = 0; i < 4; ++i) cin >> a[i];
    sort(a, a + 4);
    int c = 1;
    for(int i = 1; i < 4; ++i) if(a[i] != a[i - 1]) c++;
    cout << 4 - c;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int q;
	cin >> q;
	long long n;
	long long k;
	for (int i = 0; i < q; i++)
	{
		cin >> n;
		k = 0;
		while (n % 5 == 0)
		{
			n = n / 5 * 4;
			k += 1;
		}
		while (n % 3 == 0)
		{
			n = n / 3 * 2;
			k += 1;
		}
		while (n % 2 == 0)
		{
			n = n / 2;
			k++;
		}
		if (n != 1)
		{
			cout << "-1" << endl;
		}
		else {
			cout << k << endl;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int m=0;
        while(n!=1)
        {
            if(n%5==0)
            {
                m=m+3;
                n=n/5;
            }
            else break;
        }
        while(n!=1)
        {
            if(n%3==0)
            {
                m=m+2;
                n=n/3;
            }
            else break;
        }
        while(n!=1)
        {
            if(n%2==0)
            {
                m=m+1;
                n=n/2;
            }
            else break;
        }
        if(n==1)
        cout<<m<<endl;
        else
        cout<<-1<<endl;
    }
}


#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        unsigned long long int n;
        cin>>n;
        int m=0;
        while(n!=1)
        {
            if(n%5==0)
            {
                m=m+3;
                n=n/5;
            }
            else break;
        }
        while(n!=1)
        {
            if(n%3==0)
            {
                m=m+2;
                n=n/3;
            }
            else break;
        }
        while(n!=1)
        {
            if(n%2==0)
            {
                m=m+1;
                n=n/2;
            }
            else break;
        }
        if(n==1)
        cout<<m<<endl;
        else
        cout<<-1<<endl;
    }
}


#include <iostream>
using namespace std;
int main()
{
	int q;
	cin>>q;
	while (q--)
	{
		long long n;
		cin>>n;
		int cs=0;
		while (n%5==0)
		{
			n=n/5;
			cs+=3;
		}
		while (n%3==0)
		{
			n=n/3;
			cs+=2;
		}
		while (n%2==0)
		{
			n=n/2;
			cs++;
		}
		if(n==1)
		{
			cout<<cs<<endl;
		}
		else
		{
			cout<<-1<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <stack>
#include <unordered_set>
#include <windows.h>
#include <math.h>

#define M_PI 3.14159265358979323846
#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */

using namespace std;

//#pragma comment( lib, "winmm.lib" )

int main()
{
	//cout << "Fack you" << endl;
	//int i = 0;
	//while (++i < 10)
	//{
		//MCI_OPEN_PARMS mPar = { 0 };
		//mPar.lpstrDeviceType = reinterpret_cast<LPCWSTR>(MCI_DEVTYPE_CD_AUDIO);

		// Open device
		//mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID, (DWORD)& mPar);

		// Open tray
		//mciSendCommand(mPar.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);

		// Close tray
		//mciSendCommand(mPar.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);

		// Close device
		//mciSendCommand(mPar.wDeviceID, MCI_CLOSE, MCI_WAIT, 0);

		//cout << "Open CD" << endl;
	//}

	long long a,res, cur;
	int s;
	cin >> s;

	for (int i = 0; i < s; i++) {

		bool h = true;
		cin >> a;
		cur = a;
		int cnt = 0;

		if (a == 1) {

			cout << 0 << endl;
			continue;
		}

		while (h) {

			int m = 0;

			if (long long(4 * a) % 5 == 0) {

				cnt++; m++;
				res = long long(4 * a) / 5;
				a = res;

				if (a == 1) {
					cout << cnt << endl;
					h = false;
					continue;
				}

			}
			if (long long(2 * a) % 3 == 0) {

				cnt++; m++;
				res = long long(2 * a) / 3;
				a = res;

				if (a == 1) {
					cout << cnt << endl;
					h = false;
					continue;
				}
			}
			if (long long(a) % 2 == 0) {

				cnt++; m++;
				res = long long(a) / 2;
				a = res;

				if (a == 1) {
					cout << cnt << endl;
					h = false;
					continue;
				}

			}

			if (m == 0) {

				cout << -1 << endl;
				h = false;
				continue;
			}
		}
	}

	return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int i=0,j,T;
    long long num;
    scanf("%d",&T);
    while(i<T){
        long long counter=0;
        scanf("%lld",&num);
        while(num!=1){
            if(num%2==0){
                num=num/2;
                counter++;
            }
            else if(num%3==0){
                num=(2*num)/3;
                counter++;
            }
            else if(num%5==0){
                num=(4*num)/5;
                counter++;
            }
            else{
                counter=-1;
                printf("-1\n");
                break;
            }
        }
        if(counter>=0){
            printf("%lld\n",counter);
        }
        i++;
    }
    return 0;
}


#include<iostream>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        ll n,a=0;
        cin>>n;
        while(n>1)
        {
        if(n%2==0)
        {n=n/2;a++;}
        else if(n%3==0)
        {n=2*n/3;a++;}
        else if(n%5==0)
        {n=4*n/5;a++;}
        else
        {cout<<"-1"<<endl;break;}
        }
        if(n==1)cout<<a<<endl;

    }
    return 0;

}


#include<iostream>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        ll n,a=0;
        cin>>n;
        while(n>1)
        {
        if(n%2==0)
        {n=n/2;a++;}
        else if(n%3==0)
        {n=2*n/3;a++;}
        else if(n%5==0)
        {n=4*n/5;a++;}
        else
        cout<<"-1"<<endl;
        }
        cout<<a;

    }
    return 0;

}


#include<iostream>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        ll n,a=0;
        cin>>n;
        while(n>1)
        {
        if(n%2==0)
        {n=n/2;a++;}
        else if(n%3==0)
        {n=2*n/3;a++;}
        else if(n%5==0)
        {n=4*n/5;a++;}
        else
        {cout<<"-1"<<endl;break;}
        }
        cout<<a<<endl;

    }
    return 0;

}


#include <iostream>
using namespace std;
int main(){
	long long q,a,cou;
	cin>>q;
	while(q--){
		cin>>a;
		cou=0;
		while(a!=1){
			if(a%2==0) a=a/2;
			else if(a%3==0) a=(a/3)*2;
			else if(a%5==0) a=(a/5)*4;
			else {
				cou=-1;
				break;
			}
			cou++;
		}
		cout<<cou<<'\n';
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<set>
#include<functional>
#include<sstream>
#include"math.h"
#include<algorithm>
#include"stdio.h"
#include<stack>

int main()
{
    int q;
    long long n,ans;
    scanf("%d",&q);

    while(q--)
    {
        scanf("%I64d",&n);
        ans=0;
        while(n%5==0)
        {
            n=n/5;
            ans+=3;
        }
        while(n%3==0)
        {
            n=n/3;
            ans+=2;
        }
        while(n%2==0)
        {
            n=n/2;
            ans++;
        }
        if(n==1) printf("%I64d\n",ans);
        else printf("-1\n");
    }

    return 0;
}


//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;

const int INF= 0x3f3f3f;
const int MAXN= 1e5+10;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll a,sum;
    while(n--){
        sum=0;
        cin>>a;
        while(a%5==0&&a!=1){
            a=a/5;
            sum+=3;
        }
        while(a%3==0&&a!=1){
            a=a/3;
            sum+=2;
        }
        while(a%2==0&&a!=1){
            a=a/2;
            sum+=1;
        }
        if(a!=1)
            cout<<"-1"<<endl;
        else
            cout<<sum<<endl;
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int q; long long n;
	int ans;
	cin >> q;
	while (q--)
	{
		ios::sync_with_stdio(false);
		ans = 0;
		cin >> n;
		while (n != 1)
		{
			if (n % 2 == 0)
			{
				n /= 2;
				ans++; continue;
			}
			if (n % 3 == 0)
			{
				n = 2 * n / 3;
				ans++; continue;
			}
			if (n % 5 == 0)
			{
				n = 4 * n / 5;
				ans++; continue;
			}
			ans = -1; break;

		}
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		long long n;
		cin >> n;
		int cnt2 = 0, cnt3 = 0, cnt5 = 0;
		while (n % 2 == 0) {
			n /= 2;
			++cnt2;
		}
		while (n % 3 == 0) {
			n = (2*n)/3;
			++cnt3;
		}
		while (n % 5 == 0) {
			n = (4*n)/5;
			++cnt5;
		}
		if (n != 1) {
			cout << -1 << endl;
		} else {
			cout << cnt2 + cnt3 + cnt5 << endl;
		}
	}

	return 0;
}


#include <iostream>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		long long n;
		cin >> n;
		int cnt2 = 0, cnt3 = 0, cnt5 = 0;
		while (n % 2 == 0) {
			n /= 2;
			++cnt2;
		}
		while (n % 3 == 0) {
			n = (2*n)/3;
			++cnt3;
		}
		while (n % 5 == 0) {
			n = (4*n)/5;
			++cnt5;
		}
		if (n != 1) {
			cout << -1 << endl;
		} else {
			cout << cnt2 + cnt3 + cnt5 << endl;
		}
	}

	return 0;
}


#include <iostream>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		long long n;
		cin >> n;
		int cnt2 = 0, cnt3 = 0, cnt5 = 0;
		while (n % 2 == 0) {
			n /= 2;
			++cnt2;
		}
		while (n % 3 == 0) {
			n /=3;
			++cnt3;
		}
		while (n % 5 == 0) {
			n /=5;
			++cnt5;
		}
		if (n != 1) {
			cout << -1 << endl;
		} else {
			cout << cnt2 + 2*cnt3 + 3*cnt5 << endl;
		}
	}

	return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long n,q;
    int count_n;
    cin>>q;

    for(int i=0;i<q;i++){
        cin>>n;
        count_n=0;

        while(n!=1){
            if(n%2==0){
                n/=2;
                count_n++;
                continue;
            }
            else if(n%3==0){
                n/=3;
                n*=2;
                count_n++;
                continue;
            }
            else if(n%5==0){
                n/=5;
                n*=4;
                count_n++;
                continue;
            }
            break;
        }

        if(n==1)
            cout<<count_n<<endl;
        else
            cout<<"-1"<<endl;
    }

    return 0;
}


#include<iostream>
using namespace std;
int ans;
int main() {
	int q;
	long long n;
	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> n;
		while (n != 1) {
			if (n % 2 == 0) {
				ans++;
				n = n / 2;
			}
			else if (n % 3 == 0) {
				ans++;
				n = (n * 2) / 3;
			}
			else if (n % 5 == 0) {
				ans++;
				n = (n * 4) / 5;
			}
			else {
				break;
			}
		}
		if (n == 1) {
			cout << ans << endl;
		}
		else {
			cout << -1 << endl;
		}
		ans = 0;
	}
	return 0;
}


#include<iostream>
#define data   long long int
#define pb push_back
using namespace std;
// memset(arrray,val,sizeof(array));
void init(){
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
int main()
{
    init();
    long long int q;
    cin>>q;
    cout<<"\n";
    while(q--)
    {
     long long int n;
     cin>>n;
	 cout<<"\n";
	 long long int m,s;
	 s=0;
	 m=n;
	 while(m!=1)
	 {
	  if(m%2==0)
	  {\
	   m=m/2;
	   s++;
	   continue;
	  }
	  if(m%3==0)
	  {
	   m=(m/3)*2;
	   s++;
	   continue;
	  }
	  if(m%5==0)
	  {
	   m=(m/5)*4;
	   s++;
	   continue;
	  }
	  if(m%2!=0 || m%3!=0 || m%5!=0)
	  {
	   s=-1;
	   break;
	  }
	 }
	 cout<<s;
	 cout<<"\n";
	}
}


#include<iostream>
#include <deque>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long x;
    long long y=0;
    deque <long long>d;
    for(long long i=0;i<n;i++){
        cin>>x;
        if(x==1)
        d.push_back(0);
      else  if(x%5==0){
           while(x!=1){
               y++;
               x=(4*x)/5;
           }
           d.push_back(y);
           y=0;
        }
       else if(x%3==0){
            while(x!=1){
                y++;
                x=(2*x)/3;
            }
            d.push_back(y);
            y=0;
        }
       else if(x%2==0){
            while(x!=1){
                y++;
                x=x/2;
            }
            d.push_back(y);
            y=0;
        }
        else d.push_back(-1);

    }
    for(long long i=0;i<d.size();i++){
        cout<<d[i]<<endl;
    }
    return 0;
}


#include<iostream>
#include<deque>
#include<algorithm>
using namespace std;
int main(){
long long a,y=0,x;
cin>>a;
deque<long long>d;
for(int i=0;i<a;i++){
    cin>>x;
    if(x==1){
        d.push_back(0);
        continue;
    }
    while (x!=1){
    if(x%5==0){
        y++;
        x=(x*4)/5;
    }
    else if(x%3==0){
        y++;
       x= (x*2)/3;
    }
    else if (x%2==0){
        y++;
        x=x/2;
    }
    else{
        y=-1;
        break;
    }
}
d.push_back(y);
y=0;}
for(int i=0;i<a;i++){
    cout<<d[i]<<endl;
}
    return 0;
}


#include<iostream>
using namespace std;
const int maxn=1010;
char a1[maxn],c1[maxn];
int a[maxn],c[maxn],x=0,b,lena,lenc,i,j,d3,sum,n,p;
int main()
{
	cin>>n;
	for(j=1;j<=n;j++)
	{
		memset(a,0,sizeof(a));
		memset(c,0,sizeof(c));
		cin>>a1;
		d3=0;sum=0;
		lena=strlen(a1);
		for(i=0;i<=lena-1;i++)
		{
			a[i+1]=a1[i]-48;
		}
		while(1)
		{
			d3=0;
			for(i=1;i<=lena;i++)
			{
			    d3=d3+a[i];
			}
	    	if(a[lena]==0 || a[lena]==5) {b=5;sum=sum+3;}
	    	else if(d3%3==0) {b=3;sum=sum+2;}
	      	else if(a[lena]%2==0) {b=2;sum=sum+1;}
			else break;
	    	for (i=1;i<=lena;i++)
			{
	    		c[i]=(x*10+a[i])/b;
	    		x=(x*10+a[i])%b;
			}
    		lenc=1;
    		while (c[lenc]==0 && lenc<lena)
     		lenc++;
			p=0;
    		for(i=lenc;i<=lena;i++)
			{p=p+1;a[p]=c[i];}
			lena=p;
			memset(c,0,sizeof(c));
		}
		if(lena==1 && a[1]==1)
			cout<<sum;
		else
			cout<<-1;
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int q,m;
    long long n;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>n;
        m=0;
        while(n!=1){
           if(n%2==0){
            n=n/2;
            m++;
        }
        else if(n%3==0){
            n=2*n/3;
            m++;
        }
        else if(n%5==0){
            n=4*n/5;
            m++;
        }
        }
        cout<<m<<endl;
    }
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int q,m;
    long long n;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>n;
        m=0;
        while(n!=1){
           if(n%2==0){
            n=n/2;
            m++;
        }
        else if(n%3==0){
            n=2*n/3;
            m++;
        }
        else if(n%5==0){
            n=4*n/5;
            m++;
        }
        else{
            m=-1;
            break;
        }
        }
        cout<<m<<endl;
    }
}


#include <algorithm>
#include <iostream>
//10 8 9 5 4 8 8 10 8 1

using namespace std;
int main()
{
	long long w;
	cin >> w;
	long long a, c = 0;

	while (w != 0) {
		w--;
		cin >> a;
		while (a != 1) {
			if (a % 2 == 0) {
				a /= 2;
				c++;
			}
			else if (a % 3 == 0) {
				a *= 2;
				a /= 3;
				c++;
			}
			else if (a % 5 == 0) {
				a *= 4;
				a /= 5;
				c++;
			}
			else {
				a = 1;
				c = -1;
			}
		}
		cout << c << endl;
		c = 0;
	}

	return 0;
}


#include<algorithm>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		long long n;
		cin>>n;
		if (n==1){
			cout<<0<<endl;
			continue;
		}
		int ans = 0;
		while(n%2 == 0) {
			n /= 2;
			ans ++;
		}
		while(n%3 == 0) {
			n /= 3;
			ans += 2;
		}
		while(n%5 == 0){
			n /= 5;
			ans += 3;
		}
		if (n ==1 ) cout<<ans<<endl;
		else cout<<-1<<endl;

	}
}


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
int main()
{
	ll q, n;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		ll ans = 0;
		cin >> n;
		while (!(n % 2))
		{
			ans++;
			n/=2;
		}
		while (!(n % 3))
		{
			ans+=2;
			n/=3;
		}
		while (!(n % 5))
		{
			ans+=3;
			n/=5;
		}
		if (n == 1)
			cout << ans << endl;
		else
			cout << -1 << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

long long GCDFast(long long a, long long b){ while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
//int dx[8] = { -1, 0, 1, 0, -1, 1, 1, -1 };
//int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

#define MAX_PRIME 10001
bool flag[MAX_PRIME];
vector<LL> Prime;

void Sieve(int n)
{
	int i, j;
	for (i = 2; i*i <= n;)
	{
		for (j = i*i; j <= n; j += i)
			flag[j] = 1;
		for (i = i + 1; flag[i]; i++);
	}

	Prime.push_back(2);
	for (i = 3; i<n; i += 2)
		if (flag[i] == 0)
			Prime.push_back(i);
}
LL a[100005],X[2005];
int main() {
	//freopen ("d:/Codejam/input.txt","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, m, i, j, k, temp, x, y, sum;
	LL u, v, z, length, ans, l, r, w, num, q, test_case;
	string str;

	ios::sync_with_stdio(false);

	cin >> q;
	while (q--){
		cin >> n;
		int count = 0;
		while (n > 1){
			count++;
			if (n % 2 == 0){
				n = n / 2;
			}
			else if (n % 3 == 0){
				n = 2 * n / 3;
			}
			else if (n % 5 == 0){
				n = 4 * n / 5;
			}
			else
				break;
		}
		if (n > 1){
			cout << "-1\n";
		}
		else{
			cout << count << endl;
		}
	}

	return 0;
}


#include <iostream>

using namespace std;

int main(){
	int q;cin >> q;

	while(q--){
	long long n;cin >> n;

	int c = 0;
	while(n%2==0 || n%3==0 || n%5==0){
		c++;
		if(n%2==0){
			n/=2;
			continue;
		}

		if(n%3==0){
			n*=2;
			n/=3;
			continue;
		}
		if(n%5==0){
			n*=4;
			n/=5;
			continue;
		}
	}

	if(n==1)cout << "\t\t" << c << "\n";
	else cout << "\t\t" << -1 << "\n";

}

	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<set>
using namespace std;
#define maxn 1e18;
multiset<long long> s;
vector<long long> n,t;
int rep(long long x)
{
	long long ans=0;
	while(x!=1)
	{
		long long t=maxn;
		if(x%2!=0&&x%3!=0&&x%5!=0)
		{
			ans=-1;
			break;
		}
		else
		{
		if(x%2==0)
			t=min(x/2,t);;
		if(x%3==0)
			t=min(2*x/3,t);
		if(x%5==0)
			t=min(4*x/5,t);
		x=t;
		ans++;
		}
	}
	return ans;
}
int main()
{
	int q,l=0;
	set<long long> m;
	scanf("%d",&q);
	n.clear();
	while(q--)
	{
		long long x;
		cin>>x;
		n.push_back(x);
		l++;
	}
	for(int i=0;i<l;i++)
		cout<<rep(n[i])<<" ";
	return 0;
}


#include <iostream>
using namespace std;
void main()
{
	long long n,m,c=0;
	bool x = false;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> n;
		while (n != 1)
		{
			if (n % 2 == 0){ n = n / 2; c++; }
			else if (n % 3 == 0){ n = (2 * n) / 3; c++; }
			else if (n % 5 == 0){ n = (4 * n) / 5; c++; }
			else { x = true; break; }
		}
		if (x == true)
		{
			cout << "-1" << "\n";
		}
		else{ cout << c << "\n"; }
		c = 0;
		x = false;
	}

}


#include<stdio.h>
int ans,n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		long long temp;ans=0;
		scanf("%I64d",&temp);
		while(!(temp%2)) temp/=2,ans++;
		while(!(temp%3)) temp/=3,ans+=2;
		while(!(temp%5)) temp/=5,ans+=3;
		if((temp-1))printf("-1\n");else printf("%d\n",ans);
	}
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int T;
	cin>>T;
	while(T--)
	{
		int n,flag=0,count=0;
		cin>>n;
		for(;n!=1;count++)
		{
			if(n%2==0)
				n/=2;
			else if(n%3==0)
				n=n/3*2;
			else if(n%5==0)
				n=n/5*4;
			else
			{	flag=1;break;	}
		}
		if(flag)
			printf("-1\n");
		else
			printf("%I64d\n",count);
	}
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		long long int n;
		int flag=0,count=0;
		cin>>n;
		for(;n!=1;count++)
		{
			if(n%2==0)
				n/=2;
			else if(n%3==0)
				n=n/3*2;
			else if(n%5==0)
				n=n/5*4;
			else
			{	flag=1;break;	}
		}
		if(flag)
			printf("-1\n");
		else
			printf("%I64d\n",count);
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#pragma warning(disable:4996)
using namespace std;

long long delitel(long long n) {
	if (n == 1)
		return 0;
	else if (n % 2 == 0)
		return n / 2;
	else if (n % 3 == 0)
		return (n / 3) * 2;
	else if (n % 5 == 0)
		return (n / 5) * 4;
	else return -1;
}

int main() {
	int n;
		long long q, temp_q, otv_q;
	cin >> n;
	vector<long long>qs;
	vector<int> otv;
	for (int i = 0; i < n; i++) {
		cin >> q;
		qs.push_back(q);
	}
	for (int i = 0; i < n; i++) {
		temp_q = qs[i];
		int j = 0;
		while (true) {
			otv_q = delitel(temp_q);
			if (otv_q == 0)
				break;
			else if (otv_q == -1) {
				j = -1;
				break;
			}
			temp_q = otv_q;
			j++;
		}
		otv.push_back(j);
	}
	for (int i = 0; i < n; i++) {
		cout << otv[i];
		cout << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int q,cnt;
long long n;
int work(long long x){

	if(x==1) return cnt;
    else if(x%2==0) x/=2,cnt++,work(x);
	else if(x%3==0) x=x/3*2,cnt++,work(x);
	else if(x%5==0) x=x/5*4,cnt++,work(x);
	else if(x!=1) return cnt=-1;

}
int main()
{
	scanf("%d",&q);
	while(q--){
		scanf("%I64d",&n);
		cnt=0;
		work(n);
		printf("%d\n",cnt);
	}
 }


#include <iostream>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		int counter = 0;
		uint64_t n;
		cin >> n;
		while (n > 1) {
			if (n % 2 == 0) {
				n /= 2;
			}
			else if (n % 3 == 0) {
				n = n * 2 / 3;
			}
			else if (n % 5 == 0) {
				n = n * 4 / 5;
			}
			else {
				cout << -1 << endl;
				break;
			}
			counter++;
		}
		if (n==1) {
			cout << counter << endl;
		}

	}
}


#include <iostream>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		int counter = 0;
		long long n;
		cin >> n;
		while (n > 1) {
			if (n % 2 == 0) {
				n /= 2;
			}
			else if (n % 3 == 0) {
				n = n * 2 / 3;
			}
			else if (n % 5 == 0) {
				n = n * 4 / 5;
			}
			else {
				cout << -1 << endl;
				break;
			}
			counter++;
		}
		if (n==1) {
			cout << counter << endl;
		}

	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
#define mid ((l+r)>>1)
using namespace std;
const int N = 1000006;
LL n,ans,t,l,r,tot;
LL c2[N],c3[N],c5[N],c4[N];
int main()
{
	c2[0]=c3[0]=c5[0]=1;
	c2[1]=2; c3[1]=3; c5[1]=5;
	for(int i=2;i<=60;i++)
	 c2[i]=c2[i-1]*2,c3[i]=c3[i-1]*3,c5[i]=c5[i-1]*5,c4[N]=c4[i-1]*4;
//	cout<<c5[30]<<"*"<<endl;
	scanf("%lld",&t);
	while(t--)
	{
		ans=0;
		scanf("%lld",&n);
		while(n>1)
		{
			if(n%5==0) {n=n/5*4;++ans;continue;}
			if(n%3==0) {n=n/3*2; ++ans; continue;}
			if(n%2==0) { n/=2; ++ans; continue;}
			if(n>1) break;
		}
		if(n>1) printf("-1\n");
		else printf("%lld\n",ans);
/*		if(n==1) { printf("0\n");continue;}
		l=0,r=60;
		while(l<=r)
		{
			if(n%c2[mid]==0) tot=l,l=mid+1;
			else r=mid-1;
		}
//		cout<<tot<<"*";
		ans+=tot; n/=c2[tot];
		l=0,r=50;
		while(l<=r)
		{
			if(n%c3[mid]==0) tot=l,l=mid+1;
			else r=mid-1;
		}
//		cout<<tot<<"*";
		ans+=tot; n/=c3[tot]; n*=c2[tot];
		l=0,r=30;
		while(l<=r)
		{
			if(n%c5[mid]==0) tot=l,l=mid+1;
			else r=mid-1;
//			cout<<l<<"*"<<r<<endl;;
		}
//		cout<<endl;
//		cout<<tot<<"*"<<endl;
		ans+=tot; n/=c5[tot]; n*=c4[tot];
		if(n!=1) printf("-1\n");
		else printf("%lld\n",ans);*/
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<unordered_set>
#include<map>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
using namespace std;

int main(){

int x;
cin>>x;
long long y,sum=0;
while (x--){
	sum=0;
	cin>>y;
	while (y>1){
		if (y%2==0){
			y=y/2;
			sum++;
		}
		else if (y%3==0){
			y=y/3*2;
			sum++;
		}
		else if (y%5==0)
		{
			y=y/5*4;
			sum++;
		}
		else
			break;
	}

	if (y==1)
		cout<<sum<<endl;
	else
		cout<<-1<<endl;
}

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int q;
    cin>>q;
    unsigned long long int count=0;
    bool flag=true;
    vector<unsigned long long int> input_vect;
    for(int i=0;i<q;i++)
    {   unsigned long long int x;
        cin >> x;
        input_vect.push_back(x);
    }
    for(int i=0;i<q;i++)
    {
       if(input_vect[i]==1)
       {
           cout<<"0"<<endl;
           flag=false;
       }
       while(input_vect[i]>1)
       {
        if(input_vect[i]%2==0)
        {
            input_vect[i]/=2;
        }
        else if(input_vect[i]%3==0)
        {
            input_vect[i]=(input_vect[i]*2.0)/3.0;
        }
        else if(input_vect[i]%5==0)
        {
            input_vect[i]=(input_vect[i]*4.0)/5.0;
        }
        else
        {
            flag=false;
            cout <<"-1"<<endl;
            break;
        }
        //cout<<"value="<<input_vect[i]<<" count="<<count<<endl;
        count++;
    }
       if(flag==false)
       {

       }
       else if(flag == true)
       {
         cout<<count<<endl;
       }
      count=0;
      flag=true;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int q;
    cin>>q;
    unsigned long long int count=0;
    bool flag=true;
    unsigned long long int x=0;

    for(int i=0;i<q;i++)
    {
        cin >> x;

        if(x==1)
        {
            cout<<"0"<<endl;
            flag=false;
        }
        else {
            while(x>1)
            {
                if(x%2==0)
                {
                    x/=2;
                }
                else if(x%3==0)
                {
                    x=((x*2.0)/3.0);
                }
                else if(x%5==0)
                {
                    x=((x*4.0)/5.0);
                }
                else
                {
                    flag=false;
                    cout <<"-1"<<endl;
                    break;
                }

                count++;
            }
        }
        if(flag==false)
        {

        }
        else if(flag == true)
        {
            cout<<count<<endl;
        }
        count=0;
        flag=true;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int q;
    cin>>q;
    unsigned long long int count=0;
    bool flag=true;
    unsigned long long int x=0;

    for(int i=0;i<q;i++)
    {
        cin >> x;

        while(x>1)
        {
            if(x%2==0)
            {
                x/=2;
            }
            else if(x%3==0)
            {
                x=((x*2)/3);
            }
            else if(x%5==0)
            {
                x=((x*4)/5);
            }
            else
            {
                break;
            }

            count++;

        }

        if(x==1)
        {
            cout<<count<<endl;
        }
        else {
            cout<<"-1"<<endl;
        }
        count=0;

    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int q;
    cin>>q;
    unsigned long long int count=0;
    bool flag=true;
    unsigned long long int x=0;

    for(int i=0;i<q;i++)
    {
        cin >> x;

        while(x>1)
        {
            if(x%2==0)
            {
                x/=2;
            }
            else if(x%3==0)
            {
                x=((x*2.0)/3.0);
            }
            else if(x%5==0)
            {
                x=((x*4.0)/5.0);
            }
            else
            {
                break;
            }

            count++;

        }

        if(x==1)
        {
            cout<<count<<endl;
        }
        else {
            cout<<"-1"<<endl;
        }
        count=0;

    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int q;
    cin>>q;
    unsigned long long int count=0;
    bool flag=true;
    vector<unsigned long long int> input_vect;
    for(int i=0;i<q;i++)
    {   unsigned long long int x;
        cin >> x;
        input_vect.push_back(x);
    }
    for(int i=0;i<q;i++)
    {
       if(input_vect[i]==1)
       {
           cout<<"0"<<endl;
           flag=false;
       }
       while(input_vect[i]>1)
       {
        if(input_vect[i]%2==0)
        {
            input_vect[i]/=2;
        }
        else if(input_vect[i]%3==0)
        {
            input_vect[i]*=(2.0/3.0);
        }
        else if(input_vect[i]%5==0)
        {
            input_vect[i]*=(4.0/5.0);
        }
        else
        {
            flag=false;
            cout <<"-1"<<endl;
            break;
        }
        //cout<<"value="<<input_vect[i]<<" count="<<count<<endl;
        count++;
    }
       if(flag==false)
       {

       }
       else if(flag == true)
       {
         cout<<count<<endl;
       }
      count=0;
      flag=true;
    }

    return 0;
}