using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n,m,max=0,flag=0;
            string[] lines = Console.ReadLine().Split(' ');
            n= long.Parse(lines[0]);
            m= long.Parse(lines[1]);
            long[,] mas;
            mas=new long [m,2];
            string[] ll = Console.ReadLine().Split(' ');
            mas[0,0]=long.Parse(ll[0]);
            mas[0,1]=long.Parse(ll[1]);
            for(long j=1;j<m;j++)
            {
                 string[] l = Console.ReadLine().Split(' ');
                 mas[j,0]=long.Parse(l[0]);
                 mas[j,1]=long.Parse(l[1]);
                 if( ((mas[j,0]-mas[j-1,0])<(mas[j,1]-mas[j-1,1]))||((mas[j,0]-mas[j-1,0])<(mas[j-1,1]-mas[j,1])) )
                 {
                     flag=1;
                 }
            }

            if(flag==0)
            {
                long m1=mas[0,1]+n-mas[0,0];
               for(long j=0;j<(m-1);j++)
                {
                  m1=mas[j+1,1]+(mas[j+1,0]-mas[j,0]-mas[j+1,1]+mas[j,1])/2;
                  if(max<m1)
                   max=m1;
                }
              if(max<m1)
                   max=m1;
               Console.WriteLine(max);
            }
            else
               Console.WriteLine("IMPOSSIBLE");

        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n,m,max=0,flag=0;
            string[] lines = Console.ReadLine().Split(' ');
            n= long.Parse(lines[0]);
            m= long.Parse(lines[1]);
            long[,] mas;
            mas=new long [m,2];
            string[] ll = Console.ReadLine().Split(' ');
            mas[0,0]=long.Parse(ll[0]);
            mas[0,1]=long.Parse(ll[1]);
            for(long j=1;j<m;j++)
            {
                 string[] l = Console.ReadLine().Split(' ');
                 mas[j,0]=long.Parse(l[0]);
                 mas[j,1]=long.Parse(l[1]);
                 if( ((mas[j,0]-mas[j-1,0])<(mas[j,1]-mas[j-1,1]))||((mas[j,0]-mas[j-1,0])<(mas[j-1,1]-mas[j,1])) )
                 {
                     flag=1;
                 }
            }

            if(flag==0)
            {
                long m1=mas[0,1]+n-mas[0,0];
                max=mas[0,1]+mas[0,0]-1;
               for(long j=0;j<(m-1);j++)
                {
                  m1=mas[j+1,1]+(mas[j+1,0]-mas[j,0]-mas[j+1,1]+mas[j,1])/2;
                  if(max<m1)
                   max=m1;
                }
                m1=mas[m-1,1]+n-mas[m-1,0];
                if(max<m1)
                   max=m1;
               Console.WriteLine(max);
            }
            else
               Console.WriteLine("IMPOSSIBLE");

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C26
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] words = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(words[0]);
            int m = Convert.ToInt32(words[1]);
            int[] d = new int[m];
            int[] h = new int[m];

            words = Console.ReadLine().Split(' ');
            d[0] = Convert.ToInt32(words[0]);
            h[0] = Convert.ToInt32(words[1]);
            int max = h[0] + d[0] - 1;
            int temp;

            for (int i=1; i<m; i++)
            {
                words = Console.ReadLine().Split(' ');
                d[i] = Convert.ToInt32(words[0]);
                h[i] = Convert.ToInt32(words[1]);
                if (Math.Abs(h[i]-h[i-1])>d[i]-d[i-1])
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }
                temp = (d[i] - d[i - 1] - Math.Abs(h[i] - h[i - 1]));
                temp = Math.Max(h[i], h[i - 1]) + ((int)Math.Floor(((double)temp)/2));
                if (temp > max) max = temp;
            }
            temp = (n - d[m - 1]) + h[m - 1];
            if (temp > max) max = temp;
            Console.WriteLine(max);
           // Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prC {

    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter("output");
        private static readonly StreamReader reader = new StreamReader("input");
#endif
        static void Main(string[] args) {
            int n = Next();
            int m = Next();
            long max = 0;
            long lastD = 0;
            long lastH = 0;
            for(int i = 0; i < m; i++) {
                long d = Next();
                long h = Next();
                if(d == 1) {
                    max = h + d - 1;
                }
                else {
                    if(Math.Abs(lastH - h) > d - lastD) {
                        max = -1;
                        break;
                    }
                    else if(Math.Abs(lastH - h) == d - lastD) {
                        max = Math.Max(max, Math.Max(h, lastH));
                    }
                    else {
                        long dd = d - lastD - 1;
                        dd -= Math.Abs(lastH - h);
                        dd /= 2;
                        long q = dd += Math.Max(lastH, h);
                        max = Math.Max(max, q);
                    }
                }
                lastD = d;
                lastH = h;
            }
            if(max != -1 && lastD != n) {
                max = Math.Max(max, lastH + n - lastD);
            }
            writer.Write(max == -1 ? "IMPOSSIBLE" : max.ToString());
            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prC {

    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter("output");
        private static readonly StreamReader reader = new StreamReader("input");
#endif
        static void Main(string[] args) {
            int n = Next();
            int m = Next();
            long max = 0;
            long lastD = Next();
            long lastH = Next();
            max = lastH + lastD - 1;
            for(int i = 1; i < m; i++) {
                long d = Next();
                long h = Next();
                    if(Math.Abs(lastH - h) > d - lastD) {
                        max = -1;
                        break;
                    }
                    if(Math.Abs(lastH - h) == d - lastD) {
                        max = Math.Max(max, Math.Max(h, lastH));
                    }
                    else {
                        long dd = d - lastD - 1;
                        dd -= Math.Abs(lastH - h);
                        dd = dd / 2 + dd % 2;
                        long q = dd + Math.Max(lastH, h);
                        max = Math.Max(max, q);
                    }
                lastD = d;
                lastH = h;
            }
            if(max != -1 && lastD != n) {
                max = Math.Max(max, lastH + n - lastD);
            }
            writer.Write(max == -1 ? "IMPOSSIBLE" : max.ToString());
            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prC {

    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter("output");
        private static readonly StreamReader reader = new StreamReader("input");
#endif
        static void Main(string[] args) {
            int n = Next();
            int m = Next();
            long max = 0;
            long lastD = 0;
            long lastH = 0;
            for(int i = 0; i < m; i++) {
                long d = Next();
                long h = Next();
                if(d == 1) {
                    max = h + d - 1;
                }
                else {
                    if(Math.Abs(lastH - h) > d - lastD) {
                        max = -1;
                        break;
                    }
                    else if(Math.Abs(lastH - h) == d - lastD) {
                        max = Math.Max(max, Math.Max(h, lastH));
                    }
                    else {
                        long dd = d - lastD - 1;
                        dd -= Math.Abs(lastH - h);
                        dd = dd / 2 + dd % 2;
                        long q = dd + Math.Max(lastH, h);
                        max = Math.Max(max, q);
                    }
                }
                lastD = d;
                lastH = h;
            }
            if(max != -1 && lastD != n) {
                max = Math.Max(max, lastH + n - lastD);
            }
            writer.Write(max == -1 ? "IMPOSSIBLE" : max.ToString());
            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntMatrix(m);

        for (int i = 0; i + 1 < m; i++)
            if (Math.Abs(a[i][0] - a[i + 1][0]) < Math.Abs(a[i][1] - a[i + 1][1]))
            {
                Write("IMPOSSIBLE");
                return;
            }

        int ans = Math.Max(a[0][1] + a[0][0] - 1, a[m - 1][1] + n - a[m - 1][0]);
        for (int i = 0; i + 1 < m; i++)
        {
            int l = Math.Max(a[i][1], a[i + 1][1]);
            int r = 1000000000;
            while (l < r)
            {
                int mid = (l + r + 1) / 2;
                if (Math.Abs(mid - a[i][1]) + Math.Abs(mid - a[i + 1][1]) > a[i + 1][0] - a[i][0])
                    r = mid - 1;
                else
                    l = mid;
            }
            ans = Math.Max(ans, l);
        }
        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("hull.in");
        //writer = new StreamWriter("hull.out");
#endif
        try
        {
//            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
//            thread.Start();
//            thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() {return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);}
    public static string ReadToken(){while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine());return currentLineTokens.Dequeue();}
    public static int ReadInt(){return int.Parse(ReadToken());}
    public static long ReadLong(){return long.Parse(ReadToken());}
    public static double ReadDouble(){return double.Parse(ReadToken(), CultureInfo.InvariantCulture);}
    public static int[] ReadIntArray(){return ReadAndSplitLine().Select(int.Parse).ToArray();}
    public static long[] ReadLongArray(){return ReadAndSplitLine().Select(long.Parse).ToArray();}
    public static double[] ReadDoubleArray(){return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();}
    public static int[][] ReadIntMatrix(int numberOfRows){int[][] matrix = new int[numberOfRows][];for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray();return matrix;}
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows){int[][] matrix = ReadIntMatrix(numberOfRows);int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++){ret[i] = new int[numberOfRows];for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i];}return ret;}
    public static string[] ReadLines(int quantity){string[] lines = new string[quantity];for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim();return lines;}
    public static void WriteArray<T>(IEnumerable<T> array){writer.WriteLine(string.Join(" ", array));}
    public static void Write(params object[] array){WriteArray(array);}
    public static void WriteLines<T>(IEnumerable<T> array){foreach (var a in array)writer.WriteLine(a);}
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>{public new TValue this[TKey key]{
        get { return ContainsKey(key) ? base[key] : default(TValue); }set { base[key] = value; }}}
    private static T[] Init<T>(int size) where T : new(){var ret = new T[size];for (int i = 0; i < size; i++)ret[i] = new T();return ret;}
    #endregion
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication254
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            PairVariable[] p = new PairVariable[m];
            for (int i = 0; i < m; i++)
            {
                p[i] = new PairVariable(Console.ReadLine());
            }
            for (int i = 0; i < m - 1; i++)
            {
                if (Math.Abs(p[i].a - p[i + 1].a) < Math.Abs(p[i].b - p[i + 1].b))
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }
            }
            List<int> ans = new List<int>();
            if (p[0].a != 1)
            {
                ans.Add(p[0].b + p[0].a - 1);
            }
            if (p[m - 1].a != n)
            {
                ans.Add(p[m - 1].b + (n - p[m - 1].a));
            }
            for (int i = 0; i < m - 1; i++)
            {
                int l = 0;
                int r = 100000000;
                int c = 0;
                while (l+1 < r)
                {
                    c = (l + r) / 2;
                    if (Math.Abs(c - p[i].b) + Math.Abs(c - p[i + 1].b) <= Math.Abs(p[i].a - p[i + 1].a))
                    {
                        l = c;
                    }
                    else
                    {
                        r = c;
                    }
                }
                ans.Add(l);
            }
            Console.WriteLine(ans.Max());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication254
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            PairVariable[] p = new PairVariable[m];
            for (int i = 0; i < m; i++)
            {
                p[i] = new PairVariable(Console.ReadLine());
            }
            if (n == 1 && m == 1)
            {
                Console.WriteLine(p[0].b);
                return;
            }
            for (int i = 0; i < m - 1; i++)
            {
                if (Math.Abs(p[i].a - p[i + 1].a) < Math.Abs(p[i].b - p[i + 1].b))
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }
            }
            List<int> ans = new List<int>();
            if (p[0].a != 1)
            {
                ans.Add(p[0].b + p[0].a - 1);
            }
            if (p[m - 1].a != n)
            {
                ans.Add(p[m - 1].b + (n - p[m - 1].a));
            }
            for (int i = 0; i < m - 1; i++)
            {
                int l = Math.Min(p[i].b, p[i+1].b);
                int r = 1000000000;
                int c = 0;
                while (l+1 < r)
                {
                    c = (l + r) / 2;
                    if (Math.Abs(c - p[i].b) + Math.Abs(c - p[i + 1].b) <= Math.Abs(p[i].a - p[i + 1].a))
                    {
                        l = c;
                    }
                    else
                    {
                        r = c;
                    }
                }
                ans.Add(l);
            }
            Console.WriteLine(ans.Max());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication254
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            PairVariable[] p = new PairVariable[m];
            for (int i = 0; i < m; i++)
            {
                p[i] = new PairVariable(Console.ReadLine());
            }
            for (int i = 0; i < m - 1; i++)
            {
                if (Math.Abs(p[i].a - p[i + 1].a) < Math.Abs(p[i].b - p[i + 1].b))
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }
            }
            List<int> ans = new List<int>();
            if (p[0].a != 1)
            {
                ans.Add(p[0].b + p[0].a - 1);
            }
            if (p[m - 1].a != n)
            {
                ans.Add(p[m - 1].b + (n - p[m - 1].a));
            }
            for (int i = 0; i < m - 1; i++)
            {
                int l = Math.Min(p[i].b, p[i+1].b);
                int r = 100000000;
                int c = 0;
                while (l+1 < r)
                {
                    c = (l + r) / 2;
                    if (Math.Abs(c - p[i].b) + Math.Abs(c - p[i + 1].b) <= Math.Abs(p[i].a - p[i + 1].a))
                    {
                        l = c;
                    }
                    else
                    {
                        r = c;
                    }
                }
                ans.Add(l);
            }
            Console.WriteLine(ans.Max());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication254
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            PairVariable[] p = new PairVariable[m];
            for (int i = 0; i < m; i++)
            {
                p[i] = new PairVariable(Console.ReadLine());
            }
            for (int i = 0; i < m - 1; i++)
            {
                if (Math.Abs(p[i].a - p[i + 1].a) < Math.Abs(p[i].b - p[i + 1].b))
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }
            }
            List<int> ans = new List<int>();
            if (p[0].a != 1)
            {
                ans.Add(p[0].b + p[0].a - 1);
            }
            if (p[m - 1].a != n)
            {
                ans.Add(p[m - 1].b + (n - p[m - 1].a));
            }
            for (int i = 0; i < m - 1; i++)
            {
                int l = Math.Min(p[i].b, p[i+1].b);
                int r = 1000000000;
                int c = 0;
                while (l+1 < r)
                {
                    c = (l + r) / 2;
                    if (Math.Abs(c - p[i].b) + Math.Abs(c - p[i + 1].b) <= Math.Abs(p[i].a - p[i + 1].a))
                    {
                        l = c;
                    }
                    else
                    {
                        r = c;
                    }
                }
                ans.Add(l);
            }
            Console.WriteLine(ans.Max());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Codeforces
{
    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
        var n = ReadInt();
        var m = ReadInt();
        var dh = ReadIntMatrix(m);
        var maxHeight = 0;
        for (int i = 1; i < m; i++)
        {
            var d = dh[i][0] - dh[i - 1][0];
            var h = Math.Abs(dh[i][1] - dh[i - 1][1]);
            if (h > d)
            {
                Write("IMPOSSIBLE");
                reader.Close();
                writer.Close();
                return;
            }
            maxHeight = Math.Max(maxHeight, Math.Max(dh[i][1], dh[i - 1][1]) + d / 2 - (d % 2 == 1 ? h / 2 : (h + 1) / 2));
        }
        writer.WriteLine(m == 1 ? dh[0][1] : maxHeight);
        reader.Close();
        writer.Close();
    }
    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }
    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }
    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Codeforces
{
    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
        var n = ReadInt();
        var m = ReadInt();
        var dh = ReadIntMatrix(m);
        var maxHeight = 0;
        for (int i = 1; i < m; i++)
        {
            var d = dh[i][0] - dh[i - 1][0];
            var h = Math.Abs(dh[i][1] - dh[i - 1][1]);
            if (h > d)
            {
                Write("IMPOSSIBLE");
                reader.Close();
                writer.Close();
                return;
            }
            maxHeight = Math.Max(maxHeight, Math.Max(dh[i][1], dh[i - 1][1]) + d / 2 - (d % 2 == 1 ? h / 2 : (h + 1) / 2));
        }
        if (n > dh[m - 1][0])
        {
            var d = n - dh[m - 1][0];
            maxHeight = Math.Max(maxHeight, dh[m - 1][1] + d);
        }
        writer.WriteLine(m == 1 ? dh[0][1] + Math.Max(Math.Abs(n - dh[0][0]), dh[0][0] - 1) : maxHeight);
        reader.Close();
        writer.Close();
    }
    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }
    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }
    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }
    #endregion
}


using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Net.Sockets;
using System.Xml;
using System.Diagnostics;
using System.Linq;
using System.Threading;

static class Program
{
    #region IO
    public delegate ReadDelegate<T> ReadDelegate<T>(out T value);
    public delegate bool ParserDelegate<T>(string word, out T item);

    public class Input : IDisposable
    {
        private static EventArgs DefaultEventArgs = new EventArgs();

        public TextReader TextReader { get; private set; }

        public event EventHandler OnEndOfStream;
        public event EventHandler OnParseError;
        public event EventHandler OnReadError;

        public bool CanRead { get; private set; }
        public bool ThrowExceptions { get; set; }

        string line = string.Empty;
        int pos = 0;

        static EventHandler emptyHandler;

        public Input(string path)
            : this(File.OpenRead(path))
        {
        }
        public Input(Stream s)
            : this(new StreamReader(s))
        {

        }
        public Input(TextReader tr)
        {
            TextReader = tr;

            if (emptyHandler == null)
                emptyHandler = (a, b) => { };

            OnEndOfStream = emptyHandler;
            OnParseError = emptyHandler;
            OnReadError = emptyHandler;

            CanRead = true;
        }

        public static implicit operator Input(Stream s)
        {
            return new Input(s);
        }
        public static implicit operator Input(TextReader tr)
        {
            return new Input(tr);
        }

        private bool ReadStream()
        {
            if (!CanRead) return false;
            if (pos < line.Length) return true;

            Clear();

            string s = TextReader.ReadLine();
            if (s == null)
            {
                CanRead = false;
                return false;
            }

            line = s;
            return true;
        }

        public ReadDelegate<T> r<T>(out T value)
        {
            value = ReadData<T>();
            return r;
        }

        public void SkipChar()
        {
            if (pos < line.Length) pos++;
            else
            {
                ReadStream();
            }
        }
        public void SkipChars(int length)
        {
            while (length > 0)
            {
                int dt = line.Length - pos;
                if (dt <= 0)
                {
                    length--;
                    if (!ReadStream()) return;
                }
                dt = Math.Min(length, dt);
                pos += dt;
                length -= dt;
            }
        }

        public void SkipWhiteSpace()
        {
            while (true)
            {
                for (; pos < line.Length; pos++)
                {
                    if (!char.IsWhiteSpace(line[pos])) return;
                }
                if (!ReadStream())
                {
                    OnEndOfStream(this, DefaultEventArgs);
                    return;
                }
            }
        }
        public bool CanReadData()
        {
            SkipWhiteSpace();
            return CanRead;
        }

        public T[] ReadArray<T>()
        {
            int length = ReadInt32();
            return ReadArray<T>(length);
        }
        public T[] ReadArray<T>(int length)
        {
            ParserDelegate<T> parser = Parser.GetPrimitiveParser<T>();
            return ReadArray<T>(length, parser);
        }
        public T[] ReadArray<T>(ParserDelegate<T> parser)
        {
            int length = ReadInt32();
            return ReadArray<T>(length, parser);
        }
        public T[] ReadArray<T>(int length, ParserDelegate<T> parser)
        {
            T[] res = new T[length];
            for (int i = 0; i < length; i++)
            {
                res[i] = ReadData<T>(parser);
            }
            return res;
        }

        public Decimal ReadDecimal()
        {
            return ReadData<Decimal>(Parser.DecimalParser);
        }
        public Double ReadDouble()
        {
            return ReadData<Double>(Parser.DoubleParser);
        }
        public Single ReadSingle()
        {
            return ReadData<Single>(Parser.SingleParser);
        }
        public UInt64 ReadUInt64()
        {
            return ReadData<UInt64>(UInt64.TryParse);
        }
        public UInt32 ReadUInt32()
        {
            return ReadData<UInt32>(UInt32.TryParse);
        }
        public UInt16 ReadUInt16()
        {
            return ReadData<UInt16>(UInt16.TryParse);
        }
        public Int64 ReadInt64()
        {
            return ReadData<Int64>(Int64.TryParse);
        }
        public Int32 ReadInt32()
        {
            return ReadData<Int32>(Int32.TryParse);
        }
        public Int16 ReadInt16()
        {
            return ReadData<Int16>(Int16.TryParse);
        }
        public Boolean ReadYesNo()
        {
            return ReadData<Boolean>(Parser.YesNoParser);
        }
        public Boolean ReadBoolean()
        {
            return ReadData<Boolean>(Boolean.TryParse);
        }
        public Byte ReadByte()
        {
            return ReadData<Byte>(Byte.TryParse);
        }

        private bool ReadCheck()
        {
            if (!CanRead)
            {
                OnReadError(this, DefaultEventArgs);
                if (ThrowExceptions)
                {
                    throw new Exception("!CanRead");
                }
                return false;
            }
            return true;
        }
        public T ReadData<T>()
        {
            return ReadData<T>(true);
        }
        public T ReadData<T>(bool skipWhiteSpace)
        {
            ParserDelegate<T> parser = Parser.GetPrimitiveParser<T>();
            return ReadData<T>(parser, skipWhiteSpace);
        }
        public T ReadData<T>(ParserDelegate<T> parser)
        {
            return ReadData<T>(parser, true);
        }
        public T ReadData<T>(ParserDelegate<T> parser, bool skipWhiteSpace)
        {
            if (skipWhiteSpace)
                SkipWhiteSpace();

            if (!ReadCheck()) return default(T);

            string s = ReadWord(false);

            T res;
            if (!parser.Invoke(s, out res))
            {
                OnParseError(this, DefaultEventArgs);
                if (ThrowExceptions)
                {
                    throw new Exception("!validate, word = " + Output.ToString(s, 256));
                }
            }
            return res;
        }

        public string ReadWord()
        {
            return ReadWord(true);
        }
        public string ReadWord(bool skipWhiteSpace)
        {
            if (skipWhiteSpace)
                SkipWhiteSpace();

            if (!ReadCheck()) return string.Empty;

            int from = pos;
            int to = pos;
            for (int i = pos; i < line.Length; i++)
            {
                if (char.IsWhiteSpace(line[i])) break;
                to = i + 1;
            }
            pos = to;

            return line.Substring(from, to - from);
        }

        public string ReadLine()
        {
            if (!ReadCheck()) return string.Empty;

            ReadStream();
            string res = line.Substring(pos);
            pos = line.Length;

            return res;
        }

        public void Close()
        {
            TextReader.Close();
        }
        public void Clear()
        {
            pos = 0;
            line = string.Empty;
        }

        private bool disposed = false;
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    line = string.Empty;
                    TextReader.Dispose();
                }
                disposed = true;
            }
        }
        ~Input()
        {
            Dispose(false);
        }
    }
    public class Output : IDisposable
    {
        static char[] space = new char[] { ' ' };

        public TextWriter TextWriter { get; private set; }
        public bool AutoFlush { get; set; }

        public static string ToString(object obj, int maxLength)
        {
            return ToString(FormatReal(obj), maxLength);
        }
        public static string ToString(string s, int maxLength)
        {
            if (s.Length <= maxLength) return s;
            else return s.Substring(0, maxLength) + "...";
        }
        public static object FormatReal(object v, string format)
        {
            if (v is decimal) return ((decimal)v).ToString(format).Replace(',', '.');
            if (v is double) return ((double)v).ToString(format).Replace(',', '.');
            if (v is float) return ((float)v).ToString(format).Replace(',', '.');

            return v;
        }
        public static object FormatReal(object v)
        {
            if (v is decimal || v is double || v is float)
            {
                return v.ToString().Replace(',', '.');
            }
            return v;
        }

        public Output()
            : this(new MemoryStream())
        {
        }
        public Output(string path)
            : this(File.Create(path))
        {

        }
        public Output(Stream s)
            : this(new StreamWriter(s))
        {
        }
        public Output(TextWriter tw)
        {
            TextWriter = tw;
        }

        public static implicit operator Output(Stream s)
        {
            return new Output(s);
        }

        public static implicit operator Output(TextWriter tw)
        {
            return new Output(tw);
        }

        public static Output operator +(Output output, object obj)
        {
            output.Write(obj);
            return output;
        }
        public Output WriteArray<T>(params T[] array)
        {
            return WriteArray<T>(array, false);
        }
        public Output WriteArray<T>(T[] array, bool appendLength)
        {
            return WriteArray<T>(array, 0, array.Length, appendLength);
        }
        public Output WriteArray<T>(T[] array, int index, int count)
        {
            return WriteArray<T>(array, index, count, false);
        }
        public Output WriteArray<T>(T[] array, int index, int count, bool appendLength)
        {
            if (index + count > array.Length)
            {
                string message = string.Format(
                    "Index out of range: {0} + {1} >= {2}",
                    index,
                    count,
                    array.Length);
                throw new Exception(message);
            }
            if (appendLength)
            {
                WriteLine(count);
            }
            for (int i = 0; i < count; i++)
            {
                Write(array[i + index]);
                Write(space, 0, space.Length);
            }
            WriteLine();

            return this;
        }
        public Output WriteLine(object obj)
        {
            obj = FormatReal(obj);
            return WriteLine(obj.ToString());
        }
        public Output WriteLine(string format, params object[] args)
        {
            return WriteLine(string.Format(format, args));
        }
        public Output WriteLine(string s)
        {
            return WriteLine(s.ToCharArray());
        }
        public Output WriteLine(char[] buffer)
        {
            return WriteLine(buffer, 0, buffer.Length);
        }
        public Output WriteLine(char[] buffer, int index, int count)
        {
            TextWriter.WriteLine(buffer, index, count);
            if (AutoFlush) TextWriter.Flush();
            return this;
        }
        public Output WriteLine()
        {
            TextWriter.WriteLine();
            if (AutoFlush) TextWriter.Flush();
            return this;
        }
        public Output Write(object obj)
        {
            obj = FormatReal(obj);
            return Write(obj.ToString());
        }
        public Output Write(string format, params object[] args)
        {
            return Write(string.Format(format, args));
        }
        public Output Write(string s)
        {
            return Write(s.ToCharArray());
        }
        public Output Write(char[] buffer)
        {
            return Write(buffer, 0, buffer.Length);
        }
        public Output Write(char[] buffer, int index, int count)
        {
            TextWriter.Write(buffer, index, count);
            if (AutoFlush) TextWriter.Flush();
            return this;
        }

        public void Close()
        {
            TextWriter.Close();
        }
        public void Flush()
        {
            TextWriter.Flush();
        }

        private bool disposed = false;
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    TextWriter.Dispose();
                }
                disposed = true;
            }
        }
        ~Output()
        {
            Dispose(false);
        }
    }
    public static class Parser
    {
        public static ParserDelegate<T> GetPrimitiveParser<T>()
        {
            if (!typeof(T).IsPrimitive && typeof(T) != typeof(String)) throw new Exception("Unknown type");
            else if (default(T) is Byte) return new ParserDelegate<Byte>(Byte.TryParse) as ParserDelegate<T>;
            else if (default(T) is Boolean) return new ParserDelegate<Boolean>(Boolean.TryParse) as ParserDelegate<T>;
            else if (default(T) is Int16) return new ParserDelegate<Int16>(Int16.TryParse) as ParserDelegate<T>;
            else if (default(T) is Int32) return new ParserDelegate<Int32>(Int32.TryParse) as ParserDelegate<T>;
            else if (default(T) is Int64) return new ParserDelegate<Int64>(Int64.TryParse) as ParserDelegate<T>;
            else if (default(T) is UInt16) return new ParserDelegate<UInt16>(UInt16.TryParse) as ParserDelegate<T>;
            else if (default(T) is UInt32) return new ParserDelegate<UInt32>(UInt32.TryParse) as ParserDelegate<T>;
            else if (default(T) is UInt64) return new ParserDelegate<UInt64>(UInt64.TryParse) as ParserDelegate<T>;
            else if (default(T) is Single) return new ParserDelegate<Single>(Parser.SingleParser) as ParserDelegate<T>;
            else if (default(T) is Double) return new ParserDelegate<Double>(Parser.DoubleParser) as ParserDelegate<T>;
            else if (default(T) is Decimal) return new ParserDelegate<Decimal>(Parser.DecimalParser) as ParserDelegate<T>;
            else if (typeof(T) == typeof(String)) return new ParserDelegate<String>(Parser.StringParser) as ParserDelegate<T>;
            else throw new Exception("Unknown type");
        }
        public static bool YesNoParser(string s, out Boolean result)
        {
            s = s.ToLower();
            if (s == "yes") result = true;
            else if (s == "no") result = false;
            else
            {
                result = false;
                return false;
            }
            return true;
        }
        public static bool ReplaceDot;
        public static bool StringParser(string s, out string result)
        {
            result = s;
            return string.IsNullOrEmpty(s);
        }
        private static string fs(string s)
        {
            if (ReplaceDot) return s.Replace(',', '.');
            else return s;
        }
        public static bool DecimalParser(string s, out Decimal result)
        {
            return Decimal.TryParse(fs(s), out result);
        }
        public static bool DoubleParser(string s, out Double result)
        {
            return Double.TryParse(fs(s), out result);
        }
        public static bool SingleParser(string s, out Single result)
        {
            return Single.TryParse(fs(s), out result);
        }
    }
    #endregion
    #region Streams
    static string endl = Environment.NewLine;
    static Input cin = new Input(Console.In);
    static Output cout = new Output(Console.Out);
    static Output cerr = new Output(Console.Error);
    static StringBuilder sb = new StringBuilder();
    #endregion
    #region Time
    //*
    static Stopwatch sw = new Stopwatch();
    static void Start()
    {
        sw.Reset();
        sw.Start();
    }
    static void Restart(string text = "")
    {
        Stop(text);
        Start();
    }
    static void Time(string text = "")
    {
        if (string.IsNullOrEmpty(text))
        {
            cerr.WriteLine(sw.Elapsed);
        }
        else
        {
            cerr.WriteLine(text + ": " + sw.Elapsed);
        }
    }
    static void Stop(string text = "")
    {
        sw.Stop();
        Time(text);
    }
    //*/
    #endregion

    static void InitIO(string name)
    {
#if DEBUG
#else
        cin = new Input(name + ".in");
        cout = new Output(name + ".out");
        Parser.ReplaceDot = false;
#endif
    }
    static void Main()
    {
        var n = cin.ReadInt32();
        var m = cin.ReadInt32();

        var d1 = cin.ReadInt32();
        var h1 = cin.ReadInt32();

        var maxh = h1 + (d1 - 1);

        for(var i = 1; i < m;i++)
        {
            var d2 = cin.ReadInt32();
            var h2 = cin.ReadInt32();

            var dd = d2 - d1;
            var hh = Math.Abs(h2 - h1);

            if(hh > dd)
            {
                cout.WriteLine("IMPOSSIBLE");
                return;
            }

            var free = (dd - hh) / 2;
            maxh = Math.Max(free + Math.Max(h1, h2), maxh);

            d1 = d2;
            h1 = h2;
        }

        maxh = Math.Max(maxh, h1 + n - d1);

        cout.WriteLine(maxh);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

/*		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First > y.First || (x.First == y.First && x.Second < y.Second))
					return -1;
				return 1;
			}
		}*/

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;
			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		private static void Main()
		{
			var l = ReadListOfInts();
			var n = l[0];
			var m = l[1];
			var v = new List<Pair>();
			for (var i = 0; i < m; ++i)
			{
				l = ReadListOfInts();
				v.Add(new Pair { First = l[0], Second = l[1] });
			}
			if (v[0].First != 1)
			{
				v.Insert(0, new Pair { First = 1, Second = v[0].Second + (v[0].First - 1) });
			}
			if (v.Last().First != n)
			{
				v.Add(new Pair { First = n, Second = n - v.Last().First + v.Last().Second });
			}
			var ans = v[0].Second;
			m = v.Count();
			var can = true;
			for (var i = 1; i < m; ++i)
			{
				ans = Math.Max(ans, v[i].Second);
				var prevL = v[i - 1].Second;
				var prevD = v[i - 1].First;
				var curL = v[i].Second;
				var curD = v[i].First;
				var t = curD - prevD;
				if (curD - prevD > 1)
				{
					var cc = false;
					if ((prevL - curL + t) % 2 == 0)
					{
						var y = (prevL - curL + t) / 2;
						if (y >= 0)
							y = t - y;
						if (y >= 0)
							cc = true;
						ans = Math.Max(ans, prevL + y);
					}
					if ((prevL - curL + t - 1) % 2 == 0)
					{
						var y = (prevL - curL + t - 1) / 2;
						if (y >= 0)
							y = t - y;
						if (y >= 0)
							cc = true;
						ans = Math.Max(ans, prevL + y);
					}
					if (!cc)
						can = false;
				}
				else
				{
					if (Math.Abs(curL - prevL) > 1)
						can = false;
				}
			}
			WriteYesNo(can, ans.ToString(), "IMPOSSIBLE");
			Console.ReadLine();
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

/*		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First > y.First || (x.First == y.First && x.Second < y.Second))
					return -1;
				return 1;
			}
		}*/

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;
			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		private static void Main()
		{
			var l = ReadListOfInts();
			var n = l[0];
			var m = l[1];
			var v = new List<Pair>();
			for (var i = 0; i < m; ++i)
			{
				l = ReadListOfInts();
				v.Add(new Pair { First = l[0], Second = l[1] });
			}
			if (v[0].First != 1)
			{
				v.Insert(0, new Pair { First = 1, Second = v[0].Second + (v[0].First - 1) });
			}
			if (v.Last().First != n)
			{
				v.Add(new Pair { First = n, Second = n - v.Last().First + v.Last().Second });
			}
			var ans = v[0].Second;
			m = v.Count();
			var can = true;
			for (var i = 1; i < m; ++i)
			{
				ans = Math.Max(ans, v[i].Second);
				var prevL = v[i - 1].Second;
				var prevD = v[i - 1].First;
				var curL = v[i].Second;
				var curD = v[i].First;
				var t = curD - prevD - 1;
				if (curD - prevD > 1)
				{
					var cc = false;
					if ((prevL - curL + t) % 2 == 0)
					{
						var y = (prevL - curL + t) / 2;
						if (y >= 0)
							y = t - y;
						if (y >= 0)
							cc = true;
						ans = Math.Max(ans, prevL + y);
					}
					if ((prevL - curL + t - 1) % 2 == 0)
					{
						var y = (prevL - curL + t - 1) / 2;
						if (y >= 0)
							y = t - y;
						if (y >= 0)
							cc = true;
						ans = Math.Max(ans, prevL + y);
					}
					if (!cc)
						can = false;
				}
				else
				{
					if (Math.Abs(curL - prevL) > 1)
						can = false;
				}
			}
			WriteYesNo(can, ans.ToString(), "IMPOSSIBLE");
			Console.ReadLine();
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

/*		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First > y.First || (x.First == y.First && x.Second < y.Second))
					return -1;
				return 1;
			}
		}*/

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;
			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		private static void Main()
		{
			var l = ReadListOfInts();
			var n = l[0];
			var m = l[1];
			var v = new List<Pair>();
			for (var i = 0; i < m; ++i)
			{
				l = ReadListOfInts();
				v.Add(new Pair { First = l[0], Second = l[1] });
			}
			if (v[0].First != 1)
			{
				v.Insert(0, new Pair { First = 1, Second = v[0].Second + (v[0].First - 1) });
			}
			if (v.Last().First != n)
			{
				v.Add(new Pair { First = n, Second = n - v.Last().First + v.Last().Second });
			}
			var ans = v[0].Second;
			m = v.Count();
			var can = true;
			for (var i = 1; i < m; ++i)
			{
				ans = Math.Max(ans, v[i].Second);
				var prevL = v[i - 1].Second;
				var prevD = v[i - 1].First;
				var curL = v[i].Second;
				var curD = v[i].First;
				var t = curD - prevD;
				if (curD - prevD > 1)
				{
					var cc = false;
					if ((prevL - curL + t) % 2 == 0)
					{
						var y = (prevL - curL + t) / 2;
						if (y >= 0)
							y = t - y;
						if (y >= 0)
							cc = true;
						ans = Math.Max(ans, prevL + y);
					}
					if ((prevL - curL + t - 1) % 2 == 0)
					{
						var y = (prevL - curL + t - 1) / 2;
						if (y >= 0)
							y = t - 1 - y;
						if (y >= 0)
							cc = true;
						ans = Math.Max(ans, prevL + y);
					}
					if (!cc)
						can = false;
				}
				else
				{
					if (Math.Abs(curL - prevL) > 1)
						can = false;
				}
			}
			WriteYesNo(can, ans.ToString(), "IMPOSSIBLE");
			Console.ReadLine();
		}
	}
}


using System;
using System.IO;
using System.Collections.Generic;

class Program
{
    //////////////////////////////////////////////////

    public void Solution()
    {
        int n = ri;
        int m = ri;
        int pred_d=ri;
        int pred_h=ri;

        int res = pred_d-1+pred_h;

        int cur_d;
        int cur_h;
        for(int i=1; i<m; i++)
        {
            cur_d = ri;
            cur_h = ri;

            if (cur_h>pred_h)
            {
                pred_d+=cur_h-pred_h;
                if (pred_d>cur_d)
                {
                    wrt("IMPOSSIBLE");
                    return;
                }
                else
                {
                    res = Math.Max(cur_h + (cur_d - pred_d) / 2, res);
                }
            }
            else
            {
                int d = cur_d-(pred_h-cur_h);
                if (d<pred_d)
                {
                    wrt("IMPOSSIBLE");
                    return;
                }
                else
                {
                    res = Math.Max(res,pred_h+(d-pred_d)/2);
                }
            }

            pred_d = cur_d;
            pred_h = cur_h;

        }

        res = Math.Max(res,pred_h+n-pred_d);
        wrt(res);

    }
    //////////////////////////////////////////////////

    static void swap(ref object o1, ref object o2) { var o = o1; o1 = o2; o2 = o; }
    static void wln(object o = null) { Console.WriteLine(o); }
    static void wrt(object o) { Console.Write(o.ToString() + ' '); }

    int ri
    {
        get
        {
            _read();
            while (_str[_ind] == ' ') ++_ind;
            int sign = 1;
            if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ')
                p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind;
            return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read();
            while (_str[_ind] == ' ') ++_ind;
            int sign = 1;
            if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ')
                p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind;
            return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read();
            while (_str[_ind] == ' ') ++_ind;
            int sign = 1;
            if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            long q = 1;
            while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.')
                p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.')
            {
                ++_ind;
                while (_ind < _count && _str[_ind] != ' ')
                {
                    p = p * 10 + _str[_ind++] - '0';
                    q *= 10;
                }
            }
            while (_ind < _count && _str[_ind] == ' ') ++_ind;
            return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read();
            while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1)
            {
                _count = 0;
                _ind = 0;
                return _str.Substring(_ind);
            }
            var s = _str.Substring(_ind, tmp - _ind);
            _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind;
            return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n; )
        {
            var s = Console.ReadLine();
            var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i;
                if (i == m) break;
                int sign = 1;
                if (s[i] == '-')
                {
                    sign = -1;
                    ++i;
                }
                int p = 0;
                while (i < m && s[i] != ' ')
                    p = p * 10 + s[i++] - '0';
                res[k++] = p * sign;
            }
        }
        _count = 0;
        _ind = 0;
        return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n; )
        {
            var s = Console.ReadLine();
            var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i;
                if (i == m) break;
                int sign = 1;
                if (s[i] == '-')
                {
                    sign = -1;
                    ++i;
                }
                long p = 0;
                while (i < m && s[i] != ' ')
                    p = p * 10 + s[i++] - '0';
                res[k++] = p * sign;
            }
        }
        _count = 0;
        _ind = 0;
        return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n; )
        {
            var s = Console.ReadLine();
            var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i;
                if (i == m) break;
                int sign = 1;
                if (s[i] == '-')
                {
                    sign = -1;
                    ++i;
                }
                long p = 0;
                long q = 1;
                while (i < m && s[i] != ' ' && s[i] != '.')
                    p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.')
                {
                    ++i;
                    while (i < m && s[i] != ' ')
                    {
                        p = p * 10 + s[i++] - '0';
                        q *= 10;
                    }
                }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0;
        _ind = 0;
        return res;
    }
    string[] rsa(int n)
    {
        var res = new string[n];
        for (int k = 0; k < n; ++k)
            res[k] = Console.ReadLine();
        _count = 0;
        _ind = 0;
        return res;
    }

    string _str = null;
    int _count = 0;
    int _ind = 0;

    void _read()
    {
        if (_ind == _count)
        {
            _str = Console.ReadLine();
            _count = _str.Length;
            _ind = 0;
        }
    }

    static void Main()
    {
        //System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
        new Program().Solution();
    }
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)
    var ans = 0
    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        ans = Math.max(b,ans)
        Pair(a,b)
    }
    ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        ok = ok.and((a[i].first - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second))
        if((a[i].first - a[i - 1].first) > 2) {
            if (ok) {
                ans = Math.max(ans,
                        Math.max(a[i - 1].second, a[i].second) +
                                (Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                                        Math.abs(a[i].second - a[i - 1].second.toDouble())) / 2.0)).toInt())
            }
        }
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)

    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        Pair(a,b)
    }
    var ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)

    (1..m - 1).forEach {
        i ->
        if (ans > 0 && (a[i].first - 1 - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second))
            ans = Math.max(ans,Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() - Math.abs(a[i].second - a[i - 1].second.toDouble())) / 2.0).toInt())
        else ans = -1
    }
    println(when(ans) {
        -1 -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)

    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        Pair(a,b)
    }
    var ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        ok = ok.and((a[i].first - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second))
        if((a[i].first - a[i - 1].first) > 2) {
            if (ok && (a[i].first - 1 - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second)) {
                ans = Math.max(ans, Math.max(a[i - 1].second, a[i].second) + ((Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                        Math.abs(a[i].second.toDouble() - a[i - 1].second.toDouble())))) / 2.0).toInt())
            }
        }
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)
    var ans = 0
    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        ans = Math.max(b,ans)
        Pair(a,b)
    }
    ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        ok = ok.and((a[i].first - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second))
        if((a[i].first - a[i - 1].first) > 2) {
            if (ok && (a[i].first - 1 - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second)) {
                ans = Math.max(ans, Math.max(a[i - 1].second, a[i].second) + ((Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                        Math.abs(a[i].second.toDouble() - a[i - 1].second.toDouble())))) / 2.0).toInt())
            }
        }
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)

    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        Pair(a,b)
    }
    var ans = Math.max(a[0].first - 1 + a[0].second, n - 1 - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        if (ok && (a[i].first - 1 - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second)) {
            ans = Math.max(ans, Math.max(a[i - 1].second,a[i].second) + Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                    Math.abs(a[i].second.toDouble() - a[i - 1].second.toDouble())) / 2.0).toInt())
        }
        else ok = false
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)

    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        Pair(a,b)
    }
    var ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        if (ok && (a[i].first - 1 - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second)) {
            ans = Math.max(ans, Math.max(a[i - 1].second,a[i].second) + Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                    Math.abs(a[i].second.toDouble() - a[i - 1].second.toDouble())) / 2.0).toInt())
        }
        else ok = false
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)
    var ans = 0
    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        ans = Math.max(b,ans)
        Pair(a,b)
    }
    ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        ok = ok.and((a[i].first - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second))
        if(ok && (a[i].first - a[i - 1].first) > 1) {
                ans = Math.max(ans,
                        Math.max(a[i - 1].second, a[i].second) +
                                (Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                                        Math.abs(a[i].second - a[i - 1].second.toDouble())) / 2.0)).toInt())
        }
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)

    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        Pair(a,b)
    }
    var ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        if (ok && (a[i].first - 1 - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second)) {
            ans = Math.max(ans, Math.max(a[i - 1].second,a[i].second) + ((Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                    Math.abs(a[i].second.toDouble() - a[i - 1].second.toDouble())))) / 2.0).toInt())
        }
        else ok = false
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


var INF = 10000 * 10000 + 1

fun main(args: Array<String>) {
    var (n,m) = readLine()!!.split(' ').map(String::toInt)

    var a = Array(m) {
        var (a,b) = readLine()!!.split(' ').map(String::toInt)
        Pair(a,b)
    }
    var ans = Math.max(a[0].first - 1 + a[0].second, n - a[m - 1].first + a[m - 1].second)
    var ok = true
    (1..m - 1).forEach {
        i ->
        ok = ok.or((a[i].first - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second))
        if((a[i].first - a[i - 1].first) > 2) {
            if (ok && (a[i].first - 1 - a[i - 1].first) >= Math.abs(a[i].second - a[i - 1].second)) {
                ans = Math.max(ans, Math.max(a[i - 1].second, a[i].second) + ((Math.ceil(((a[i].first - 1 - a[i - 1].first).toDouble() -
                        Math.abs(a[i].second.toDouble() - a[i - 1].second.toDouble())))) / 2.0).toInt())
            }
        }
    }
    println(when(ok) {
        false -> "Impossible".toUpperCase()
        else -> ans
    })
}


#include <stdio.h>
#include <stdlib.h>

#define max(a, b) (((a) > (b)) ? (a) : (b))

typedef struct {
    int d, h;
} Rec;

Rec rec[100000];

int main(void) {
    int i;
    int n, m;
    int ans;

    scanf("%d %d", &n, &m);
    for (i = 0; i < m; i++)
        scanf("%d %d", &rec[i].d, &rec[i].h);

    ans = -1;
    for (i = 0; i < m - 1; i++)
        if (abs(rec[i].h - rec[i + 1].h) > rec[i + 1].d - rec[i].d) {
            puts("IMPOSSIBLE");
            return 0;
        } else
            ans = max(ans, max(rec[i].h, rec[i + 1].h) + (rec[i + 1].d - rec[i].d - abs(rec[i].h - rec[i + 1].h)) / 2);
    ans = max(ans, rec[0].h + rec[0].d - 1);
    ans = max(ans, rec[m - 1].h + n - rec[m - 1].d);

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define max(a, b) (((a) > (b)) ? (a) : (b))

typedef struct {
    int d, h;
} Rec;

Rec rec[100001];

int main(void) {
    int i;
    int n, m;
    int ans;

    scanf("%d %d", &n, &m);
    rec[0] = (Rec){1, 0};
    for (i = 1; i <= m; i++)
        scanf("%d %d", &rec[i].d, &rec[i].h);

    ans = -1;
    for (i = 0; i < m; i++)
        if (abs(rec[i].h - rec[i + 1].h) > rec[i + 1].d - rec[i].d) {
            puts("IMPOSSIBLE");
            return 0;
        } else
            ans = max(ans, max(rec[i].h, rec[i + 1].h) + (rec[i + 1].d - rec[i].d - abs(rec[i].h - rec[i + 1].h)) / 2);
    ans = max(ans, rec[m].h + n - rec[m].d);

    printf("%d\n", ans);

    return 0;
}


#include "stdio.h"
#include "math.h"

int max(int x,int y){
    return x>y?x:y;
}
int main(int argc, char* argv[])
{
    int n,m,d,h;
    scanf("%d%d",&n,&m);
    scanf("%d%d",&d,&h);
    int d1=d;
    int h1=h;
    int ans=h+d-1;
    //第一段从1到d，向下爬，最大为第一天；
    int f=1;
    int i,t;
    for(i=0;i<m-1;i++){
        scanf("%d%d",&d,&h);
        if(abs(h-h1)>d-d1)
            f=0;
        else
            t=(d-d1+h+h1)/2;
        ans=max(ans,t);
    }//每一段求最大值；
    t=n-d+h;//最后一段；
    ans=max(t,ans);
    if(f==0)
        printf("IMPOSSIBLE\n");
    else
        printf("%d\n",ans);

    return 0;
}


#include "stdio.h"
#include "math.h"

int max(int x,int y){
    return x>y?x:y;
}
int main(int argc, char* argv[])
{
    int n,m,d,h;
    scanf("%d%d",&n,&m);
    scanf("%d%d",&d,&h);
    int d1=d;
    int h1=h;
    int ans=h+d-1;
    //第一段从1到d，向下爬，最大为第一天；
    int f=1;
    int i,t;
    for(i=0;i<m-1;i++){
        scanf("%d%d",&d,&h);
        if(abs(h-h1)>d-d1)
            f=0;
        else
            t=(d-d1+h+h1)/2;
        ans=max(ans,t);
        d1=d;
        h1=h;
    }//每一段求最大值；
    t=n-d1+h1;//最后一段；
    ans=max(t,ans);
    if(f==0)
        printf("IMPOSSIBLE\n");
    else
        printf("%d\n",ans);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define MAXM 100096
#define max(_a, _b) ((_a) > (_b) ? (_a) : (_b))

int main()
{
    int n, m, i;
    int d[MAXM], h[MAXM];
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; ++i) scanf("%d%d", &d[i], &h[i]);

    int impossible = 0, maxh = -1;
    for (i = 1; i < m; ++i)
        if (abs(d[i] - d[i - 1]) < abs(h[i] - h[i - 1])) {
            impossible = 1; break;
        } else {
            int t = abs(d[i] - d[i - 1]) - abs(h[i] - h[i - 1]),
                dh = max(h[i], h[i - 1]);
            maxh = max(maxh, dh + t / 2);
        }
    if (impossible) puts("IMPOSSIBLE");
    else {
        // Tricky samples T^T
        maxh = max(maxh, h[0] + d[0]);
        maxh = max(maxh, h[m - 1] + n - d[m - 1]);
        printf("%d\n", maxh);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define MAXM 100096
#define max(_a, _b) ((_a) > (_b) ? (_a) : (_b))

int main()
{
    int n, m, i;
    int d[MAXM], h[MAXM];
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; ++i) scanf("%d%d", &d[i], &h[i]);

    int impossible = 0, maxh = -1;
    for (i = 1; i < m; ++i)
        if (abs(d[i] - d[i - 1]) < abs(h[i] - h[i - 1])) {
            impossible = 1; break;
        } else {
            int t = abs(d[i] - d[i - 1]) - abs(h[i] - h[i - 1]),
                dh = max(h[i], h[i - 1]);
            maxh = max(maxh, dh + t / 2);
        }
    if (impossible) puts("IMPOSSIBLE");
    else {
        // Tricky samples T^T
        maxh = max(maxh, h[0] + d[0] - 1);
        maxh = max(maxh, h[m - 1] + n - d[m - 1]);
        printf("%d\n", maxh);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define MAXM 10096
#define max(_a, _b) ((_a) > (_b) ? (_a) : (_b))

int main()
{
    int n, m, i;
    int d[MAXM], h[MAXM];
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; ++i) scanf("%d%d", &d[i], &h[i]);

    int impossible = 0, maxh = -1;
    for (i = 1; i < m; ++i)
        if (abs(d[i] - d[i - 1]) < abs(h[i] - h[i - 1])) {
            impossible = 1; break;
        } else {
            int t = abs(d[i] - d[i - 1]) - abs(h[i] - h[i - 1]),
                dh = max(h[i], h[i - 1]);
            maxh = max(maxh, dh + t / 2);
        }
    if (impossible) puts("IMPOSSIBLE");
    else printf("%d\n", maxh);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define MAXM 100096
#define max(_a, _b) ((_a) > (_b) ? (_a) : (_b))

int main()
{
    int n, m, i;
    int d[MAXM], h[MAXM];
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; ++i) scanf("%d%d", &d[i], &h[i]);

    int impossible = 0, maxh = -1;
    for (i = 1; i < m; ++i)
        if (abs(d[i] - d[i - 1]) < abs(h[i] - h[i - 1])) {
            impossible = 1; break;
        } else {
            int t = abs(d[i] - d[i - 1]) - abs(h[i] - h[i - 1]),
                dh = max(h[i], h[i - 1]);
            maxh = max(maxh, dh + t / 2);
        }
    if (impossible) puts("IMPOSSIBLE");
    else printf("%d\n", maxh);
    return 0;
}


#include <stdio.h>
#define INT_MAX 100000000
#define MMAX 100000

int highest(int pd, int ph, int cd, int ch)
{
    int l=ph,r=INT_MAX;
    while (r-l>1)
    {
        int m=(r+l)/2;
        if (2*m-ph-ch<=cd-pd)
            l=m;
        else
            r=m;
    }
    return l;
}

int main()
{
    int n,m,i,pd,ph,cd,ch,rs=0;
    scanf("%d%d",&n,&m);
    for (i=0;i<m;i++)
    {
        scanf("%d%d",&cd,&ch);
        if (i>0)
            if (cd-pd<abs(ch-ph))
            {
                rs=-1;
                break;
            }
            else
            {
                int temp=highest(pd,ph,cd,ch);
                rs=(rs>temp)?rs:temp;
            }
        else
            rs=(rs>ch+cd-1)?rs:(ch+cd-1);
        pd=cd;
        ph=ch;
    }
    if (rs==-1)
        printf("IMPOSSIBLE");
    else
        printf("%d",rs>(ph+n-pd)?rs:(ph+n-pd));
    return 0;
}


#include <stdio.h>
#define INT_MAX 200000000
#define MMAX 100000

int highest(int pd, int ph, int cd, int ch)
{
    int l=ph,r=INT_MAX;
    while (r-l>1)
    {
        int m=(r+l)/2;
        if (2*m-ph-ch<=cd-pd)
            l=m;
        else
            r=m;
    }
    return l;
}

int main()
{
    int n,m,i,pd,ph,cd,ch,rs=0;
    scanf("%d%d",&n,&m);
    for (i=0;i<m;i++)
    {
        scanf("%d%d",&cd,&ch);
        if (i>0)
            if (cd-pd<abs(ch-ph))
            {
                rs=-1;
                break;
            }
            else
            {
                int temp=highest(pd,ph,cd,ch);
                rs=(rs>temp)?rs:temp;
            }
        else
            rs=(rs>ch+cd-1)?rs:(ch+cd-1);
        pd=cd;
        ph=ch;
    }
    if (rs==-1)
        printf("IMPOSSIBLE");
    else
        printf("%d",rs>(ph+n-pd)?rs:(ph+n-pd));
    return 0;
}


#include <stdio.h>
#define MMAX 100000

int highest(int pd, int ph, int cd, int ch)
{
    int l=pd,r=cd+1;
    while (r-l>1)
    {
        int m=(r+l)/2;
        if (2*m+ph-ch<=cd-pd)
            l=m;
        else
            r=m;
    }
    return l;
}

int main()
{
    int n,m,i,pd,ph,cd,ch,rs=0;
    scanf("%d%d",&n,&m);
    for (i=0;i<m;i++)
    {
        scanf("%d%d",&cd,&ch);
        if (i>0)
            if (cd-pd<abs(ch-ph))
            {
                rs=-1;
                break;
            }
            else
            {
                int temp=highest(pd,ph,cd,ch);
                rs=(rs>temp)?rs:temp;
            }
        pd=cd;
        ph=ch;
    }
    if (rs==-1)
        printf("IMPOSSIBLE");
    else
        printf("%d",rs>(ph+n-pd)?rs:(ph+n-pd));
    return 0;
}


#include <stdio.h>
#define MMAX 100000

int highest(int pd, int ph, int cd, int ch)
{
    int l=pd,r=cd+1;
    while (r-l>1)
    {
        int m=(r+l)/2;
        if (2*m+ph-ch<=cd-pd)
            l=m;
        else
            r=m;
    }
    return (ph+l-pd);
}

int main()
{
    int n,m,i,pd,ph,cd,ch,rs=0;
    scanf("%d%d",&n,&m);
    for (i=0;i<m;i++)
    {
        scanf("%d%d",&cd,&ch);
        if (i>0)
            if (cd-pd<abs(ch-ph))
            {
                rs=-1;
                break;
            }
            else
            {
                int temp=highest(pd,ph,cd,ch);
                rs=(rs>temp)?rs:temp;
            }
        pd=cd;
        ph=ch;
    }
    if (rs==-1)
        printf("IMPOSSIBLE");
    else
        printf("%d",rs>(ph+n-pd)?rs:(ph+n-pd));
    return 0;
}


#include <stdio.h>
#include <math.h>
int main(){

int n,m,i,aux,aux1,x,y,pos=1,max=0;
scanf("%d %d",&n,&m);
scanf("%d %d",&aux,&aux1);
max=aux1+aux-1;
for(i=1;i<m;i++){
    scanf("%d %d",&x,&y);
    if(x-aux<abs(aux1-y)){
        pos=0;
        break;
    }
    if((x-aux+y+aux1-1)/2>max);
    max=(x-aux+y+aux1-1)/2;
    aux=x;aux1=y;
}
if(max<y+n-x)
max=y+n-x;
if(pos==0)
    printf("IMPOSSIBLE");
if(pos==1)
printf("%d",max);
return 0;
}


#include <stdio.h>
#include <math.h>
int main(){

int n,m,i,aux,aux1,x,y,pos=1,max=0;
scanf("%d %d",&n,&m);
scanf("%d %d",&aux,&aux1);
max=aux1+aux-1;
if(max<aux1)
max=aux1;
for(i=1;i<m;i++){
    scanf("%d %d",&x,&y);
    if(x-aux<abs(aux1-y)){
        pos=0;
        break;
    }
    if((x-aux+y+aux1)/2>max)
    max=(x-aux+y+aux1)/2;
    if(y>max)
    max=y;
    aux=x;
    aux1=y;
}
if(max<aux1+n-aux)
max=aux1+n-aux;
if(pos==0)
    printf("IMPOSSIBLE");
if(pos==1)
printf("%d",max);
return 0;
}


#include <stdio.h>
#include <math.h>
int main(){

int n,m,i,aux,aux1,x,y,pos=1,max=0;
scanf("%d %d",&n,&m);
scanf("%d %d",&aux,&aux1);
max=aux1+aux-1;
for(i=1;i<m;i++){
    scanf("%d %d",&x,&y);
    if(x-aux<abs(aux1-y)){
        pos=0;
        break;
    }
    if((x-aux+y+aux1-1)/2>max)
    max=(x-aux+y+aux1-1)/2;
    aux=x;
    aux1=y;
}
if(max<y+n-x)
max=y+n-x;
if(pos==0)
    printf("IMPOSSIBLE");
if(pos==1)
printf("%d",max);
return 0;
}


#include <stdio.h>
#include <math.h>
int main(){

int n,m,i,aux,aux1,x,y,pos=1,max=0;
scanf("%d %d",&n,&m);
scanf("%d %d",&aux,&aux1);
max=aux1+aux-1;
for(i=1;i<m;i++){
    scanf("%d %d",&x,&y);
    if(x-aux<abs(aux1-y)){
        pos=0;
        break;
    }
    if((x-aux+y+aux1-1)/2>max)
    max=(x-aux+y+aux1-1)/2;
    if(y>max)
    max=y;
    aux=x;
    aux1=y;
}
if(max<aux1+n-aux)
max=aux1+n-aux;
if(pos==0)
    printf("IMPOSSIBLE");
if(pos==1)
printf("%d",max);
return 0;
}


#include <stdio.h>
#include <math.h>
int main(){

int n,m,i,aux,aux1,x,y,pos=1,max=0;
scanf("%d %d",&n,&m);
scanf("%d %d",&aux,&aux1);
max=aux1+aux-1;
for(i=1;i<m;i++){
    scanf("%d %d",&x,&y);
    if(x-aux<abs(aux1-y)){
        pos=0;
        break;
    }
    if((x-aux+y+aux1-1)/2>max)
    max=(x-aux+y+aux1-1)/2;
    if(y>max)
    max=y;
    aux=x;
    aux1=y;
}
if(max<y+n-x)
max=y+n-x;
if(pos==0)
    printf("IMPOSSIBLE");
if(pos==1)
printf("%d",max);
return 0;
}


#include <stdio.h>
#include <math.h>
int main(){

int n,m,i,aux,aux1,x,y,pos=1,max=0;
scanf("%d %d",&n,&m);
scanf("%d %d",&aux,&aux1);
for(i=1;i<m;i++){
    scanf("%d %d",&x,&y);
    if(x-aux<abs(aux1-y)){
        pos=0;
        break;
    }
    if((x-aux+y+aux1-1)/2>max);
    max=(x-aux+y+aux1-1)/2;
    aux=x;aux1=y;
}
if(pos==0)
    printf("IMPOSSIBLE");
if(pos==1)
printf("%d",max);
return 0;
}


#include<stdio.h>
long long int diff(long long int x,long long int y){
	if(x>y)
		return x-y;
	else
		return y-x;
}
long long int min(long long int x,long long int y){
	if(x>y)
		return x;
	else
		return y;
}
int main(){
	long long int i,j,k,l,n,m,a[2][100007],max=0;
	scanf("%lld%lld",&n,&m);
	int flag = 1;
	for(i=0;i<m;i++)
		scanf("%lld%lld",&a[0][i],&a[1][i]);
	if(m==1){
		if(a[0][0] < n/2)
			max = a[1][0] + n-a[0][0];
		else
			max = a[1][0] + a[0][0];
		flag=0;
	}
	else{
		if(a[1][0] + a[0][0] > max)
			max = a[1][0] + a[0][0];
		for(i=1;i<m;i++){
			if(diff(a[1][i],a[1][i-1]) > diff(a[0][i],a[0][i-1])){
				printf("IMPOSSIBLE\n");
				flag = 0;
				break;
			}
			else{
				if((diff(a[0][i],a[0][i-1]) - diff(a[1][i],a[1][i-1]))/2 + min(a[1][i],a[1][i-1]) > max)
					max = (diff(a[0][i],a[0][i-1]) - diff(a[1][i],a[1][i-1]))/2 + min(a[1][i],a[1][i-1]);
			}
		}
		if(n-a[0][m-1]+a[1][m-1]>max)
			max = n-a[0][m-1]+a[1][m-1];
	}
	if(flag==1)
		printf("%lld\n",max);
	return 0;
}


#include<stdio.h>
long long int diff(long long int x,long long int y){
	if(x>y)
		return x-y;
	else
		return y-x;
}
long long int min(long long int x,long long int y){
	if(x>y)
		return x;
	else
		return y;
}
int main(){
	long long int i,j,k,l,n,m,a[2][100007],max=0;
	scanf("%lld%lld",&n,&m);
	int flag = 1;
	for(i=0;i<m;i++)
		scanf("%lld%lld",&a[0][i],&a[1][i]);
	if(a[1][0] > 1){
		printf("IMPOSSIBLE\n");
		flag = 0;
	}
	else{
		for(i=1;i<m;i++){
			if(diff(a[1][i],a[1][i-1]) > diff(a[0][i],a[0][i-1])){
				printf("IMPOSSIBLE\n");
				flag = 0;
				break;
			}
			else{
				if((diff(a[0][i],a[0][i-1]) - diff(a[1][i],a[1][i-1]))/2 + min(a[1][i],a[1][i-1]) > max)
					max = (diff(a[0][i],a[0][i-1]) - diff(a[1][i],a[1][i-1]))/2 + min(a[1][i],a[1][i-1]);
			}
		}
	}
	if(flag==1)
		printf("%lld\n",max);
	return 0;
}


# include <stdio.h>
# include <conio.h>
# include <math.h>

int main()
{

    long int n,m;
    scanf("%ld%ld",&n,&m);

    long int data[2][m+1];
    long int i;
    for(i=1;i<=m;i++)
    {
        scanf("%ld%ld",&data[0][i],&data[1][i]);
    }

    int flag=0;long int max,g,v;

    max=data[1][1];
    if(data[0][1]>1)
    {
        max=data[0][1]+data[1][1]-1;
    }

    i=2;
    while(flag==0&&i<=m)
    {
       if(abs(data[0][i]-data[0][i-1])>=abs(data[1][i]-data[1][i-1]))
        {

               if(data[1][i]>data[1][i-1])
               {
                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i]+v/2)max=data[1][i]+v/2;
               }
                else
                {
                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i-1]+v/2)max=data[1][i-1]+v/2;
                }

        }
       else
        {
            flag=1;
        }
        i++;
    }
    if(data[0][m]<n)
    {
        if(max<data[1][m]+n-data[0][m])max=data[1][m]+n-data[0][m];
    }
    if(flag==1) printf("IMPOSSIBLE");
    else
    {
        printf("%ld",max);
    }
    return 0;
}


# include <stdio.h>
# include <conio.h>
# include <math.h>

int main()
{

    long int n,m;
    scanf("%ld%ld",&n,&m);

    long int data[2][m+1];
    long int i;
    for(i=1;i<=m;i++)
    {
        scanf("%ld%ld",&data[0][i],&data[1][i]);
    }

    int flag=0;long int max,g,v;

    max=data[1][1];
    if(data[0][1]>1)
    {
        max=data[0][1]+data[1][1];
    }

    i=2;
    while(flag==0&&i<=m)
    {
       if(abs(data[0][i]-data[0][i-1])>=abs(data[1][i]-data[1][i-1]))
        {

               if(data[1][i]>data[1][i-1])
               {
                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i]+v/2)max=data[1][i]+v/2;
               }
                else
                {
                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i-1]+v/2)max=data[1][i-1]+v/2;
                }

        }
       else
        {
            flag=1;
        }
        i++;
    }
    if(flag==1) printf("IMPOSSIBLE");
    else
    {
        printf("%ld",max);
    }

    return 0;
}


# include <stdio.h>
# include <conio.h>
# include <math.h>

int main()
{

    long int n,m;
    scanf("%ld%ld",&n,&m);

    long int data[2][m+1];
    long int i;
    for(i=1;i<=m;i++)
    {
        scanf("%ld%ld",&data[0][i],&data[1][i]);
    }

    int flag=0;long int max,g,v;

    max=data[1][1];
    if(data[0][1]>1)
    {
        max=data[0][1]+data[1][1];
    }

    i=2;
    while(flag==0&&i<=m)
    {
       if(abs(data[0][i]-data[0][i-1])>=abs(data[1][i]-data[1][i-1]))
        {

                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i]+v/2)max=data[1][i]+v/2;

        }
       else
        {
            flag=1;
        }
        i++;
    }
    if(flag==1) printf("IMPOSSIBLE");
    else
    {
        printf("%ld",max);
    }

    return 0;
}


# include <stdio.h>
# include <conio.h>
# include <math.h>

int main()
{

    long int n,m;
    scanf("%ld%ld",&n,&m);

    long int data[2][m+1];
    long int i;
    for(i=1;i<=m;i++)
    {
        scanf("%ld%ld",&data[0][i],&data[1][i]);
    }

    int flag=0;long int max,g,v;

    max=data[1][1];
    if(data[0][1]>1)
    {
        max=data[0][1]+data[1][1];
    }

    i=2;
    while(flag==0&&i<=m)
    {
       if(abs(data[0][i]-data[0][i-1])>=abs(data[1][i]-data[1][i-1]))
        {

               if(data[1][i]>data[1][i-1])
               {
                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i]+v/2)max=data[1][i]+v/2;
               }
                else
                {
                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i-1]+v/2)max=data[1][i-1]+v/2;
                }

        }
       else
        {
            flag=1;
        }
        i++;
    }
    if(data[0][m]<n)
    {
        if(max<data[1][m]+n-data[0][m])max=data[1][m]+n-data[0][m];
    }
    if(flag==1) printf("IMPOSSIBLE");
    else
    {
        printf("%ld",max);
    }
    return 0;
}


# include <stdio.h>
# include <conio.h>
# include <math.h>

int main()
{

    long int n,m;
    scanf("%ld%ld",&n,&m);

    long int data[2][m+1];
    long int i;
    for(i=1;i<=m;i++)
    {
        scanf("%ld%ld",&data[0][i],&data[1][i]);
    }

    int flag=0;long int max,g,v;

    max=data[1][1];
    if(data[0][1]>1)
    {
        max=data[0][1]+data[1][1];
    }

    i=2;
    while(flag==0&&i<=m)
    {
       if(abs(data[0][i]-data[0][i-1])>abs(data[1][i]-data[1][i-1]))
        {

                  g =abs(data[1][i]-data[1][i-1]);
                  v = data[0][i]-data[0][i-1]-g;

                  if(max<data[1][i]+v/2)max=data[1][i]+v/2;

        }
       else
        {
            flag=1;
        }
        i++;
    }
    if(flag==1) printf("IMPOSSIBLE");
    else
    {
        printf("%ld",max);
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

struct hd {
    int d;
    int h;
};

int main(int argc, char *argv[]) {
    int n, m;
    scanf("%d %d", &n, &m);

    struct hd *hdlist;
    hdlist = (struct hd *)malloc(m);

    int i;
    for (i = 0; i < m; i++) {
        scanf("%d %d", &(hdlist[i].d), &(hdlist[i].h));
    }

    int consistent = 1;
    int highest = 0;
    struct hd last = hdlist[0];
    for (i = 1; i < m; i++) {
        int b = last.d, bh = last.h, bl = last.h;
        int e = hdlist[i].d;
        int eh = hdlist[i].h + (e - b);
        int el = hdlist[i].h - (e - b);
        int j;
        for (j = b; j <= e; j++, bh++, bl--, eh--, el++) {
            if (bl > eh || el > bh) {
                consistent = 0;
                break;
            }

            int max = eh;
            if (bh < eh) {
                max = bh;
            }

            if (max > highest) {
                highest = max;
            }
        }

        last = hdlist[i];
    }

    if (consistent != 0) {
        printf("%d\n", highest);
    } else {
        printf("IMPOSSIBLE\n");
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

struct hd {
    int d;
    int h;
};

int main(int argc, char *argv[]) {
    int n, m;
    scanf("%d %d", &n, &m);

    struct hd *hdlist;
    hdlist = (struct hd *)malloc(m);

    int i;
    for (i = 0; i < m; i++) {
        scanf("%d %d", &(hdlist[i].d), &(hdlist[i].h));
    }

    int consistent = 1;
    int highest = 0;
    struct hd last = hdlist[0];
    struct hd end = hdlist[m-1];

    highest = (last.d - 1) + last.h;
    if ((n - end.d + end.h) > highest)
        highest = n - end.d + end.h;
    for (i = 1; i < m; i++) {
        int b = last.d, bh = last.h, bl = last.h;
        int e = hdlist[i].d;
        int eh = hdlist[i].h + (e - b);
        int el = hdlist[i].h - (e - b);
        int j;

        if (hdlist[i].h > highest)
            highest = hdlist[i].h;

        for (j = b; j <= e; j++, bh++, bl--, eh--, el++) {
            if (bl > eh || el > bh) {
                consistent = 0;
                break;
            }

            int max = eh;
            if (bh < eh) {
                max = bh;
            }

            if (max > highest) {
                highest = max;
            }
        }

        last = hdlist[i];
    }

    if (consistent != 0) {
        printf("%d\n", highest);
    } else {
        printf("IMPOSSIBLE\n");
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define llu long long int
int main()
{
    llu t,L,v,l,r;
    cin>>t;
    while(t--)
    {
        cin>>L>>v>>l>>r;
        llu count=((l-1)/v)+(L-(r+1))/v;
        if((L-(r+1))%v==0)
            count++;
        cout<<count<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define llu long long int
int main()
{
    llu t,L,v,l,r;
    cin>>t;
    while(t--)
    {
        cin>>L>>v>>l>>r;
        llu count=((l-1)/v)+(L-(r+1))/v;
        //cout<<count<<endl;
        if((r+1)%v==0)
            count++;
        cout<<count<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    lli i,t,L,v,l,r;
    cin>>t;
    while(t--)
    {
        cin>>L>>v>>l>>r;
        int ans=L/v;
        int t1=r/v;
        int t2=l/v;
        int t=t1-t2;
        if(l%v==0)
            t++;
        int count=ans-t;
        cout<<count<<endl;
    }
}


#include<bits/stdc++.h>

using namespace std ;

int main( )
{
    int T;
    scanf("%d",&T);
    while(T--)
    {

    int L,v,l,r;
    scanf("%d%d%d%d",&L,&v,&l,&r);
    int sum=0,i;
    int S=L/v;

   if(l%v==0)
    i=l;
   else
    i=(l/v+1)*v;
    if(i>r)
    {
         printf("%d\n",S);
         continue;
    }
    else if(i==r)
    {
        printf("%d\n",S-1);
    }
    else
    {
        sum=(r-i)/v+1;
        printf("%d\n",S-sum);
    }

    }
}