#include <bits/stdc++.h>
const double EPS = 1e-9;
const int oo = 1e7;
const long long OO = 1e15;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, 1, 0, -1};
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  int x, y;
  cin >> x >> y;
  int mx = y + x - 1;
  int nx = x, ny = y;
  for (int i = 1; i < m; ++i) {
    cin >> nx >> ny;
    if (nx - x < abs(ny - y)) {
      cout << "IMPOSSIBLE";
      return 0;
    }
    for (int a = x; a <= nx; ++a) {
      if (nx - a - 1 <= abs(ny - y)) break;
      y++;
    }
    if (ny > y) y = ny;
    mx = max(mx, y);
    x = nx;
    y = ny;
  }
  cout << max(mx, n - nx + ny) << '\n';
}
