#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, m, ans = 0, lastX = -1, lastY = -1, h, d;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    if (lastX == -1) {
      lastX = x;
      lastY = y;
      ans = x + y - 1;
      d = x;
      h = y;
      continue;
    }
    if (abs(lastY - y) >= x - lastX + 1) {
      cout << "IMPOSSIBLE" << endl;
      return 0;
    }
    while (d < x - 1) {
      if (h <= y)
        h++;
      else if (h - y + 1 < x - d)
        h++;
      else
        h--;
      ans = max(ans, h);
      d++;
    }
    d = x;
    h = y;
    lastX = x;
    lastY = y;
    ans = max(ans, h);
  }
  ans = max(ans, h + n - d);
  cout << ans << endl;
  return 0;
}
