#include <bits/stdc++.h>
using namespace std;
int getMidH(int st, int ed, int sh, int eh) {
  if (sh > eh) swap(sh, eh);
  int ad = eh - sh;
  st = st + ad;
  int l = st + 1, r = ed - 1;
  int ret = eh;
  while (l <= r) {
    ret++;
    l++, r--;
  }
  return ret;
}
int main() {
  int n, m;
  int pre = 0;
  int prh = 0;
  while (cin >> n >> m) {
    cin >> pre;
    cin >> prh;
    int cur = pre, cuh = prh;
    int hx = prh;
    bool isok = true;
    for (int i = 1; i < m; i++) {
      scanf("%d%d", &cur, &cuh);
      if (cur - pre < abs(cuh - prh)) {
        isok = false;
      }
      if (!isok) continue;
      hx = max(hx, cuh);
      hx = max(hx, getMidH(pre, cur, prh, cuh));
      pre = cur;
      prh = cuh;
    }
    hx = max(hx, cuh + n - cur);
    if (m == 1) hx = max(hx, cuh + cur - 1);
    if (isok)
      cout << hx << endl;
    else
      puts("IMPOSSIBLE");
  }
}
