1.

/**
* Angewandte Mathematik, SS11
* Problem: 10329 - Combinatorial Expression
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1270
*
* @author Markus Schöllner
* @author Andreas Maier
* @version 1.0, 05/22/2011
*
* Method : Ad-Hoc
* Status : Time Limit Exceeded
* Runtime:
*/

import java.math.BigInteger;
import java.util.Scanner;


public class Main {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
int nMinusR;
int counter;
BigInteger numerator = BigInteger.ONE;
BigInteger denumerator = BigInteger.ONE;
BigInteger resultNumerator = BigInteger.ONE;
BigInteger resultDenumerator = BigInteger.ONE;
BigInteger result;

int A = input.nextInt();
int B = input.nextInt();
int n;
int r;

while (true){
for(int c = 0; c <A; c++) {
n = input.nextInt();
r = input.nextInt();

if(n!=r){
numerator = BigInteger.ONE;
denumerator = BigInteger.ONE;

nMinusR = n-r;
if(nMinusR > r) {
counter = nMinusR;
nMinusR = 1;
}
else {
counter = r;
r = 1;
}
for(int i=n; i>counter;i--){
numerator = numerator.multiply((BigInteger.valueOf(i)));
}
for(int i=1; i<=nMinusR;i++){
denumerator = denumerator.multiply(BigInteger.valueOf(i));
}
for(int i=1; i<=r;i++){
denumerator = denumerator.multiply(BigInteger.valueOf(i));
}
resultNumerator = resultNumerator.multiply(numerator.divide(denumerator));
}
}

for(int c = 0; c <B; c++) {
n = input.nextInt();
r = input.nextInt();

if(n!=r){
numerator = BigInteger.ONE;
denumerator = BigInteger.ONE;
nMinusR = n-r;
if(nMinusR > r) {
counter = nMinusR;
nMinusR = 1;
}
else {
counter = r;
r = 1;
}

for(int i=n; i>counter;i--){
numerator = numerator.multiply((BigInteger.valueOf(i)));
}
for(int i=1; i<=nMinusR;i++){
denumerator = denumerator.multiply(BigInteger.valueOf(i));
}
for(int i=1; i<=r;i++){
denumerator = denumerator.multiply(BigInteger.valueOf(i));
}
resultDenumerator = resultDenumerator.multiply(numerator.divide(denumerator));
}
}

if(resultNumerator.mod(resultDenumerator)!=BigInteger.ZERO) System.out.println("0");
else {
result = resultNumerator.divide(resultDenumerator);
if(result.bitCount() < 101) System.out.println(result);
else System.out.println("-1");
}
resultNumerator = BigInteger.ONE;
resultDenumerator = BigInteger.ONE;
A = input.nextInt();
B = input.nextInt();
}
}


}