#include <bits/stdc++.h>
using namespace std;
pair<int, int> ara[(100010)];
bool check(int i, int mid) {
  int tm;
  if (mid > ara[i + 1].second) {
    tm = (mid - ara[i].second) + (mid - ara[i + 1].second);
  } else {
    tm = (mid - ara[i].second) + (ara[i + 1].second - mid);
  }
  if (tm <= (ara[i + 1].first - ara[i].first)) {
    return 1;
  }
  return 0;
}
int bin_sea(int i) {
  int lo = ara[i].second;
  int hi = 1000000000;
  bool hoise = 0;
  while (lo < hi) {
    int mid = lo + ((hi - lo + 1) / 2);
    if (check(i, mid)) {
      lo = mid;
      hoise = 1;
    } else {
      hi = mid - 1;
    }
  }
  if (check(i, lo)) {
    return lo;
  } else {
    return -1;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= m - 1; i++) {
    cin >> ara[i].first >> ara[i].second;
  }
  int mx = 0;
  mx = max(mx, ara[0].second + (ara[0].first - 1));
  for (int i = 0; i <= m - 2; i++) {
    int sv = bin_sea(i);
    if (sv == -1) {
      cout << "IMPOSSIBLE\n";
      return 0;
    }
    mx = max(mx, sv);
  }
  mx = max(mx, ara[m - 1].second + (n - ara[m - 1].first));
  cout << mx << "\n";
  return 0;
}
