
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int W = Integer.parseInt(input[0]);
int N = Integer.parseInt(input[1]);
for (int i = 0; i < N; i++) {
String[] dayInput = br.readLine().split(" ");
int c = Integer.parseInt(dayInput[0]);
int e = Integer.parseInt(dayInput[1]);
if (c > e && W <= 80) {
W++;
} else if (c < e && W >= 10) {
W--;
} else if (c == e) {
continue;
}
}
System.out.println(W);
}
}