#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s[6], i, c[6], maxp, minp;
  scanf("%d %d", &N, &M);
  for (i = 0; i < M; i++) scanf("%d %d", &s[i], &c[i]);
  maxp = s[0];
  minp = s[0];
  for (i = 0; i < M; i++) {
    if (s[i] > maxp) maxp = s[i];
    if (s[i] < minp) minp = s[i];
    if (c[i] > maxp) maxp = c[i];
    if (c[i] < minp) minp = c[i];
  }
  printf("%d\n", maxp * 100 + minp + 1);
  return 0;
}
