#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, d, h, ah, mh, i, day;
  cin >> n >> m >> d >> h;
  mh = h + (d - 1);
  ah = h;
  day = d;
  for (i = 1; i < m; i++) {
    cin >> d >> h;
    for (day = day + 1; day < d; day++) {
      if ((ah + 1) - (d - day) <= h) {
        ah++;
      } else if ((ah - 1) + (d - day) >= h) {
        ah--;
      }
      mh = (mh > ah ? mh : ah);
    }
    if (abs(ah - h) <= 1) {
      day = d;
      ah = h;
      mh = (mh > ah ? mh : ah);
    } else {
      cout << "IMPOSSIBLE" << endl;
      return 0;
    }
  }
  cout << (mh > h + (n - d) ? mh : h + (n - d)) << endl;
  return 0;
}
