import java.io.*;
import java.util.*;
public class Main {
static int[] numbers[];
static int[][] ingredients;
static boolean[] isSelected;
static int N, result;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
N = Integer.parseInt(br.readLine());
result = Integer.MAX_VALUE;
ingredients = new int[N][2];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
ingredients[i][0] = Integer.parseInt(st.nextToken());
ingredients[i][1] = Integer.parseInt(st.nextToken());
}
isSelected = new boolean[N];
SubSet(0);
sb.append(result);
System.out.println(sb);
}
static void SubSet(int cnt) {
if (cnt == N) {
int s_sum = 1;
int b_sum = 0;
for (int i = 0; i < ingredients.length; i++) {
if (isSelected[i]) {
s_sum *= ingredients[i][0];
b_sum += ingredients[i][1];
}
}
if (b_sum != 0) {
int diff = Math.abs(s_sum - b_sum);
if (result > diff) result = diff;
}
return;
}
isSelected[cnt] = true;
SubSet(cnt + 1);
isSelected[cnt] = false;
SubSet(cnt + 1);
}
}