import java.util.Scanner; class no185{ public static void main(String[] args) { Scanner stdIn=new Scanner(System.in); int n,x,y,i,t=0; n=stdIn.nextInt(); for(i=0;i0&&t!=y-x||x>=y) { t=-1; break; } t=y-x; } System.out.print(t); } }