
fun main(args:Array<String>):Unit {
    while(true){
        val n = readLine()!!.trim().toInt()
        val m = readLine()!!.trim().toInt()
        if (n == 0 && m == 0) return
        val student = Array(n){a -> Array(n){b -> a == b}}
        repeat(m){
            val (a ,b) = readLine()!!.trim().split(' ').map(String::toInt)
            student[a - 1][b - 1] = true
            student[b - 1][a - 1] = true
        }
        val square = student.map{ line ->
            (0 until n).map{x ->
                (0 until n).any{y -> student[y][x] && line[y]}
            }.toTypedArray()
        }.toTypedArray()
        println(square[0].count{it} - 1)
    }

}


