fun main(args:Array<String>?): Unit {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val professors = Array(m){
        val (a, b) = readLine()!!.trim().split(' ').map{it.toInt() - 1}
        Pair(a, b)
    }
    println(solve(n, professors) ?: "Impossible")
}
fun solve(room: Int, professors: Array<Pair<Int, Int>>): Int? {
    val sorted = professors.sortedBy{it.first}
    tailrec fun sub(current: Int, covered: Int, count: Int = 0): Int? {
        return if (covered == room - 1) count
        else if (current == professors.size) null
        else {
            val prof = (current until sorted.size).takeWhile{sorted[it].first <= covered + 1}
            if (prof.isNotEmpty()) sub(current + prof.size, prof.map { sorted[it].second }.max() ?: covered, count + 1)
            else null
        }
    }
    return sorted.takeWhile{it.first == 0}.map{it.second}.max()?.let{covered -> sub(0,  covered, 1)}
}
