#include <iostream>
#include <stdio.h>
#include <string>
#include <memory.h>
using namespace std;
typedef long long ll;
class LuckySum{
public:
	string s,res;
	bool dp[32][10][2][2];
	int v[3]={0,4,7};
	bool calc(int i,int h,bool s1,bool s2){
		if(i==s.size())
			return h==0 && s1 && s2;
		if(dp[i][h][s1][s2])
			return false;
		dp[i][h][s1][s2]=true;
		for(int d=!i;d<10;++d)
			for(int newH=0;newH<10;++newH){
				if(s[i]!='?' && s[i]-'0'!=d)
					continue;
				for(int a=s1;a<3;++a)
					for(int b=s2;b<3;++b){
						if((v[a]+v[b]+newH)/10!=h || (v[a]+v[b]+newH)%10!=d)
							continue;
						res+=d+'0';
						if(calc(i+1,newH,a>0,b>0))
							return true;
						res.resize(res.size()-1);
					}
			}
		return false;
	}
	long long construct(string note){
		s=note;
		memset(dp,0,sizeof(dp));
		res="";
		if(calc(0,0,0,0)){
			ll n;
			sscanf(&res[0],"%lld",&n);
			return n;
		}
		return -1;
	}
};
int main()
{
	string s;
	cin>>s;
	LuckySum q;
	cout<<q.construct(s)<<endl;
}