#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[3], b[2];
while(cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1])
{
if(a[0] == 0 && a[1] == 0 && a[2] == 0 && b[0] == 0 && b[1] == 0)
break;
map<int, int> mp;
mp[a[0]] = 1;
mp[a[1]] = 1;
mp[a[2]] = 1;
mp[b[0]] = 1;
mp[b[1]] = 1;
int last = 53;
sort(a, a+3);
sort(b, b+2);
if(a[2] < b[0])
{
int t = 1;
while(mp[t] == 1)
t++;
if(last > t)
last = t;
}
if(a[2] < b[1])
{
int t = a[2] + 1;
while(mp[t] == 1)
t++;
if(last > t)
last = t;
}
if(a[1] < b[0])
{
int t = a[1] + 1;
while(mp[t] == 1)
t++;
if(last > t)
last = t;
}
if(last == 53)
last = -1;
cout << last << "\n";
}
return 0;
}
using namespace std;
int main()
{
int a[3], b[2];
while(cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1])
{
if(a[0] == 0 && a[1] == 0 && a[2] == 0 && b[0] == 0 && b[1] == 0)
break;
map<int, int> mp;
mp[a[0]] = 1;
mp[a[1]] = 1;
mp[a[2]] = 1;
mp[b[0]] = 1;
mp[b[1]] = 1;
int last = 53;
sort(a, a+3);
sort(b, b+2);
if(a[2] < b[0])
{
int t = 1;
while(mp[t] == 1)
t++;
if(last > t)
last = t;
}
if(a[2] < b[1])
{
int t = a[2] + 1;
while(mp[t] == 1)
t++;
if(last > t)
last = t;
}
if(a[1] < b[0])
{
int t = a[1] + 1;
while(mp[t] == 1)
t++;
if(last > t)
last = t;
}
if(last == 53)
last = -1;
cout << last << "\n";
}
return 0;
}
Comments
Post a Comment