#include <iostream>
using namespace std;
const int N = 100010;
int expect, add;
int a[N][2];
int main() {
int i = 1;
cin >> expect;
while (cin >> a[i][0] >> a[i][1] && a[i][0] != -1 && a[i][1] != -1) {
i ++;
if (i > 2 && a[i - 1][0] - a[i - 2][0] > 1) {
i --;
int D_value = (a[i - 1][1] - a[i][1]) / (a[i][0] - a[i - 1][0]);
int t = a[i][0];
for (int j = a[i - 1][0] + 1; j <= t; j ++) {
a[i][0] = j, a[i][1] = a[i - 1][1] - D_value;
i ++;
}
}
}
i --;
cin >> add;
while (true) {
if (a[i - 1][1] - add < 0) break;
i ++;
a[i][0] = a[i - 1][0] + 1;
a[i][1] = a[i - 1][1] - add;
}
for (int k = 1; k <= 100000; k ++) {
int res = -0x3f3f3f3f, prices = 0;
for (int j = 1; j <= i; j ++) {
int price = (a[k][0] - a[1][0] + j) * a[k][1];
if (price >= res) {
res = price;
prices = a[k][0];
}
}
if (prices == expect) {
cout << k << endl;
return 0;
}
res = -0x3f3f3f3f, prices = 0;
for (int j = 1; j <= i; j ++) {
int price = (a[k][0] - a[1][0] - j) * a[k][1];
if (price >= res) {
res = price;
prices = a[k][0];
}
}
if (prices == expect) {
cout << -k << endl;
return 0;
}
}
puts("NO SOLUTION");
return 0;
}