#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPG1lbW9yeS5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKY2xhc3MgTHVja3lTdW17CnB1YmxpYzoKCXN0cmluZyBzLHJlczsKCWJvb2wgZHBbMzJdWzEwXVsyXVsyXTsKCWludCB2WzNdPXswLDQsN307Cglib29sIGNhbGMoaW50IGksaW50IGgsYm9vbCBzMSxib29sIHMyKXsKCQlpZihpPT1zLnNpemUoKSkKCQkJcmV0dXJuIGg9PTAgJiYgczEgJiYgczI7CgkJaWYoZHBbaV1baF1bczFdW3MyXSkKCQkJcmV0dXJuIGZhbHNlOwoJCWRwW2ldW2hdW3MxXVtzMl09dHJ1ZTsKCQlmb3IoaW50IGQ9IWk7ZDwxMDsrK2QpCgkJCWZvcihpbnQgbmV3SD0wO25ld0g8MTA7Kytu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