# include<bits/stdc++.h>
using namespace std;
int n, ans = 100000000;
struct p{
int s, k;
}a[11];
int book[11];
void dfs(int step, int sour, int b) {
if(step > n) {
ans = min(abs(sour - b), ans);
return;
}
book[step] = 1;
dfs(step + 1, sour * a[step].s, b + a[step].k);
book[step] = 0;
book[step] = 2;
dfs(step + 1, sour, b);
book[step] = 0;
}
int main() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i].s >> a[i].k;
dfs(1, 1, 0);
cout << ans;
return 0;
}