#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define mmt(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define N 1020
using namespace std;
typedef long long LL;
typedef long double LD;
int p[7]={0,1,5,10,20,50,100};
int g[7]={0,1,5,10,10,50,100};
void noans(){printf("impossible\n");exit(0);}
void down(int &a,int b){a=b<a?b:a;}
int dp0[N][N],dp1[N][N],t01,t12,t20,b[3],c[3],w[3][7],n[3],nx[3];
int main()
{
ios::sync_with_stdio(false);
int i,j,n0,n1,n2,k1,k2,sum=0;
scanf("%d%d%d",&t01,&t12,&t20);
FOR(i,0,2)
{
b[i]=0;
ROF(j,6,1) {scanf("%d",&w[i][j]);b[i]+=w[i][j]*p[j];}
c[i]=b[i];sum+=b[i];
}
c[0]-=t01;c[1]+=t01;
c[1]-=t12;c[2]+=t12;
c[2]-=t20;c[0]+=t20;
FOR(i,0,2) if (c[i]<0) noans();
mmt(dp0,0x3f);
dp0[b[0]][b[1]]=0;
FOR(i,1,6)
{
mmt(dp1,0x3f);
for(n0=c[0]%g[i];n0<=sum;n0+=g[i])
for(n1=c[1]%g[i];n1<=sum-n0;n1+=g[i])
{
n2=sum-n0-n1;
if (abs(c[2]-n2)%g[i]!=0) continue;
if (dp0[n0][n1]==0x3f3f3f3f) continue;
n[0]=n0;n[1]=n1;n[2]=n2;
FOR(j,0,2)
{
FOR(k1,0,w[j][i])
FOR(k2,0,w[j][i]-k1)
{
nx[(j+1)%3]=n[(j+1)%3]+p[i]*k1;
nx[(j+2)%3]=n[(j+2)%3]+p[i]*k2;
nx[j]=n[j]-p[i]*(k1+k2);
down(dp1[nx[0]][nx[1]],dp0[n[0]][n[1]]+k1+k2);
}
FOR(k1,0,w[(j+1)%3][i])
FOR(k2,0,w[(j+2)%3][i])
{
nx[(j+1)%3]=n[(j+1)%3]-p[i]*k1;
nx[(j+2)%3]=n[(j+2)%3]-p[i]*k2;
nx[j]=n[j]+p[i]*(k1+k2);
down(dp1[nx[0]][nx[1]],dp0[n[0]][n[1]]+k1+k2);
}
}
}
memcpy(dp0,dp1,sizeof(dp1));
}
if (dp0[c[0]][c[1]]==0x3f3f3f3f) printf("impossible\n");
else printf("%d\n",dp0[c[0]][c[1]]);
return 0;
}