#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class EllysNumberGuessing { public:
	int getNumber(vector <int> guesses, vector <int> answers)
	{
		set<int> cand;
		for(int i=0; i<guesses.size(); ++ i) {
			set<int> c;
			int a = guesses[i]+answers[i];
			if(1<=a && a<=1000000000) c.insert(a);
			a = guesses[i]-answers[i];
			if(1<=a && a<=1000000000) c.insert(a);

			if(i==0)
				cand = c;
			else {
				set<int> cc;
				set_intersection(cand.begin(), cand.end(), c.begin(), c.end(), inserter(cc, cc.begin()));
				cand = cc;
			}
		}
		return cand.size()==1 ? *cand.begin() : cand.size()==2 ? -1 : -2;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, EllysNumberGuessing().getNumber(guesses, answers));}
int main(){

CASE(0)
	int guesses_[] = {600, 594};
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = {6, 12};
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = 606; 
END
CASE(1)
	int guesses_[] = {100, 50, 34, 40};
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = {58, 8, 8, 2};
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = 42; 
END
CASE(2)
	int guesses_[] = {500000, 600000, 700000};
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = {120013, 220013, 79987};
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = -2; 
END
CASE(3)
	int guesses_[] = {500000000};
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = {133742666};
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = -1; 
END
CASE(4)
	int guesses_[] = {76938260, 523164588, 14196746, 296286419, 535893832,
 41243148, 364561227, 270003278, 472017422, 367932361,
 395758413, 301278456, 186276934, 316343129, 336557549,
 52536121, 98343562, 356769915, 89249181, 335191879};
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = {466274085, 20047757, 529015599, 246925926, 7318513,
 501969197, 178651118, 273209067, 71194923, 175279984,
 147453932, 241933889, 356935411, 226869216, 206654796,
 490676224, 444868783, 186442430, 453963164, 208020466};
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = 543212345; 
END
CASE(5)
	int guesses_[] = {42};
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = {42};
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = 84; 
END
CASE(6)
	int guesses_[] = {999900000};
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = {100001};
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = 999799999; 
END
/*
CASE(7)
	int guesses_[] = ;
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = ;
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = ; 
END
CASE(8)
	int guesses_[] = ;
	  vector <int> guesses(guesses_, guesses_+sizeof(guesses_)/sizeof(*guesses_)); 
	int answers_[] = ;
	  vector <int> answers(answers_, answers_+sizeof(answers_)/sizeof(*answers_)); 
	int _ = ; 
END
*/
}
// END CUT HERE
