package main

import "fmt"

func main() {
	n, m := 0, 0
	count := 0
	fmt.Scanf("%d %d\n", &n, &m)
	f := initf(m)
	for i := 0; i < n; i++ {
		l, r := 0, 0
		fmt.Scanf("%d %d\n", &l, &r)
		for j := l; j <= r; j++ {
			if !f[j] {
				count++
			}
			f[j] = true

		}
	}
	fmt.Println(m - count)
	if count != m {
		flag := false
		for i := 1; i <= m; i++ {
			if !f[i] {
				if flag {
					fmt.Print(" ", i)
				} else {
					fmt.Print(i)
					flag = true
				}
			}
		}
	}
}
func initf(len int) []bool {
	f := make([]bool, len+1)
	for i := 0; i < len+1; i++ {
		f[i] = false
	}
	return f
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, m, l, r int
	var flag [100]bool
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &m)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &l, &r)
		for j := l - 1; j < r; j++ {
			flag[j] = true
		}
	}
	count := 0
	for i := 0; i < m; i++ {
		if !flag[i] {
			count++
		}
	}
	fmt.Println(count)
	for i := 0; i < m; i++ {
		if !flag[i] {
			fmt.Printf("%d ", i+1)
		}
	}
	fmt.Println()
}

package main

import "fmt"

func main() {
	var n,m int
	fmt.Scan(&n)
	fmt.Scan(&m)
	a:=make([]int,m+2)
	for i:=0;i<n;i++ {
		var l,r int
		fmt.Scan(&l)
		fmt.Scan(&r)
		for j:=l;j<=r;j++ {
			a[j]=1
		}
	}
	kol:=m
	for i:=1;i<=m;i++ {
		kol-=a[i]
	}
	fmt.Println(kol)
	for i:=1;i<=m;i++ {
		if 0==a[i] {
			fmt.Printf("%d ",i)
		}
	}
}

// A. Points in Segments
/*
You are given a set of 𝑛 segments on the axis 𝑂𝑥, each segment has integer endpoints between 1 and 𝑚 inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers 𝑙𝑖 and 𝑟𝑖 (1≤𝑙𝑖≤𝑟𝑖≤𝑚) — coordinates of the left and of the right endpoints.

Consider all integer points between 1 and 𝑚 inclusive. Your task is to print all such points that don't belong to any segment. The point 𝑥 belongs to the segment [𝑙;𝑟] if and only if 𝑙≤𝑥≤𝑟.

Input
The first line of the input contains two integers 𝑛 and 𝑚 (1≤𝑛,𝑚≤100) — the number of segments and the upper bound for coordinates.

The next 𝑛 lines contain two integers each 𝑙𝑖 and 𝑟𝑖 (1≤𝑙𝑖≤𝑟𝑖≤𝑚) — the endpoints of the 𝑖-th segment. Segments may intersect, overlap or even coincide with each other. Note, it is possible that 𝑙𝑖=𝑟𝑖, i.e. a segment can degenerate to a point.

Output
In the first line print one integer 𝑘 — the number of points that don't belong to any segment.

In the second line print exactly 𝑘 integers in any order — the points that don't belong to any segment. All points you print should be distinct.

If there are no such points at all, print a single integer 0 in the first line and either leave the second line empty or do not print it at all.

Examples
Input
3 5
2 2
1 2
5 5

Output
2
3 4

Input
1 7
1 7

Output
0

Note
In the first example the point 1 belongs to the second segment, the point 2 belongs to the first and the second segments and the point 5 belongs to the third segment. The points 3 and 4 do not belong to any segment.

In the second example all the points from 1 to 7 belong to the first segment.
*/
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	i1 := strings.Split(strings.TrimSpace(input1), " ")
	n, _ := strconv.Atoi(i1[0])
	m, _ := strconv.Atoi(i1[1])

	ans := map[int]int{}
	for i := 1; i <= m; i++ {
		ans[i]++
	}

	for ; n > 0; n-- {
		input2, _ := reader.ReadString('\n')
		i2 := strings.Split(strings.TrimSpace(input2), " ")
		li, _ := strconv.Atoi(i2[0])
		ri, _ := strconv.Atoi(i2[1])

		for i := li; i <= ri; i++ {
			ans[i] = 0
		}
	}

	t1 := 0
	t2 := ""
	for k, v := range ans {
		if v != 0 {
			t2 += fmt.Sprintf("%v ", k)
			t1++
		}
	}
	fmt.Printf("%v\n%v", t1, t2)
}

package main

import (
	. "fmt"
)

func main() {
	var n, m, l, r int
	Scan(&n, &m)

	marks := make([]bool, m+1)
	for n > 0 {
		n--

		Scan(&l, &r)
		for i := l; i <= r; i++ {
			marks[i] = true
		}
	}

	cnt := 0
	for i := 1; i <= m; i++ {
		if !marks[i] {
			cnt++
		}
	}
	Println(cnt)
	for i := 1; i <= m; i++ {
		if !marks[i] {
			Printf("%d ", i)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)
	// fmt.Scanf("%d %d", &n, &m)
	a := make([]int, m+1)
	for i := n; i > 0; i-- {
		var s, e int
		// fmt.Scanf("%d %d", &s, &e)
		fmt.Scan(&s)
		fmt.Scan(&e)
		for j := s; j <= e; j++ {
			a[j] = 1
		}
	}
	ans := make([]int, 0)
	for i := 1; i <= m; i++ {
		if a[i] != 1 {
			ans = append(ans, i)
		}
	}
	fmt.Println(len(ans))
	for _, k := range ans {
		fmt.Printf("%d ", k)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	f := make([]int, m+1)
	for i := 0; i < n; i++ {
		a, b := 0, 0
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		for j := a; j <= b; j++ {
			f[j] = 1
		}
	}
	ans := 0
	ansList := []int{}
	for i := 1; i <= m; i++ {
		if f[i] == 0 {
			ans++
			ansList = append(ansList, i)
		}
	}
	//fmt.Println(ans, cnt)
	fmt.Fprintf(out, "%d\n", ans)
	if ans > 0 {
		fmt.Fprintf(out, "%d", ansList[0])
		for i := 1; i < len(ansList); i++ {
			fmt.Fprintf(out, " %d", ansList[i])
		}
		fmt.Fprintf(out, "\n")
	}
	return
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	dic := map[int]struct{}{}

	for range make([]struct{}, n) {
		var l, r int
		fmt.Scan(&l, &r)

		for i := l; i <= r; i++ {
			dic[i] = struct{}{}
		}
	}

	fmt.Println(m - len(dic))
	flg := false
	for i := 1; i <= m; i++ {
		if flg {
			fmt.Print(" ")
		}
		if _, in := dic[i]; !in {
			fmt.Print(i)
			flg = true
		}
	}
	fmt.Println()
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	n, m := ScanInt(), ScanInt()
	ma := make([]bool, m+1)

	for i := 0; i < n; i++ {
		l, r := ScanInt(), ScanInt()
		for j := l; j <= r; j++ {
			ma[j] = true
		}
	}

	k := 0
	ans := []int{}
	for i := 1; i <= m; i++ {
	    if !ma[i] {
	    	k++
			ans = append(ans, i)
		}
	}
	P(k)
	P(SArr(ans))
	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := MX_INT, MN_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

// Task: A. Points in Segments
// Link: http://codeforces.com/contest/1015/problem/A
// Lang: go

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanln(&n, &m)
	ma := make(map[int]bool)
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Scanln(&l, &r)
		for j := l; j <= r; j++ {
			ma[j] = true
		}
	}

	ans := make([]int, 0)
	for i := 1; i <= m; i++ {
		if !ma[i] {
			ans = append(ans, i)
		}
	}

	fmt.Println(len(ans))
	for _, x := range ans {
		fmt.Printf("%d ", x)
	}
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var a [105][2]int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i][0], &a[i][1])
	}

	ret := make([]int, 0)
	for i := 1; i <= m; i++ {
		ok := true
		for j := 0; j < n; j++ {
			if a[j][0] <= i && i <= a[j][1] {
				ok = false
			}
		}

		if ok {
			ret = append(ret, i)
		}
	}

	fmt.Println(len(ret))
	for _, v := range ret {
		fmt.Printf("%v ", v)
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	n := ScanInt()
	m := ScanInt()
	count := m
	array := make([]int, m+1)
	for i := 0; i < n; i++ {
		l := ScanInt()
		r := ScanInt()
		for j := l; j <= r; j++ {
			array[j] = 1
		}
	}

	outputArray := []int{}
	for i := 1; i <= m; i++ {
		count -= array[i]
		if 0 == array[i] {
			outputArray = append(outputArray, i)
		}
	}
	fmt.Println(count)
	fmt.Print(SArr(outputArray))

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e8))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(1e5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	n := ScanInt()
	m := ScanInt()
	count := 0
	array := make([]bool, m+1)
	for i := 0; i < n; i++ {
		l := ScanInt()
		r := ScanInt()
		for j := l; j <= r; j++ {
			array[j] = true
		}
	}
	//fmt.Println(array)
	outputArray := []int{}
	for i := 1; i <= m; i++ {
		if !array[i]{
			count++
			outputArray = append(outputArray, i)
		}
		//count -= array[i]
		//if 0 == array[i] {
		//
		//}
	}
	fmt.Println(count)
	fmt.Print(SArr(outputArray))

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e8))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(1e5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	n, m := ScanInt(), ScanInt()
	count := 0
	array := make([]bool, m+1)
	var outputArray []int
	for i := 0; i < n; i++ {
		l, r := ScanInt(), ScanInt()
		for j := l; j <= r; j++ {
			array[j] = true
		}
	}

	for i := 1; i <= m; i++ {
		if !array[i]{
			count++
			outputArray = append(outputArray, i)
		}
		//count -= array[i]
		//if 0 == array[i] {
		//
		//}
	}
	fmt.Println(count)
	fmt.Print(SArr(outputArray))

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e8))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(1e5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	n, m := ScanInt(), ScanInt()
	count := m
	array := make([]int, m+1)
	for i := 0; i < n; i++ {
		l, r := ScanInt(), ScanInt()
		for j := l; j <= r; j++ {
			array[j] = 1
		}
	}

	for i := 1; i <= m; i++ {
		count -= array[i]
	}
	fmt.Println(count)

	for i := 1; i <= m; i++ {
		if 0 == array[i] {
			fmt.Print(i," ")
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e8))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(1e5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main(){
	n := ScanInt()
	m := ScanInt()
	count := m
	array := make([]int, m+1)
	for i := 0; i< n; i++{
		l := ScanInt()
		r := ScanInt()
		for j:= l; j<=r; j++{
			array[j] = 1
		}
	}

	for i := 1; i<= m; i++{
		count -= array[i]
	}
	fmt.Println(count)

	for i := 1; i<= m; i++{
		if 0==array[i]{
			fmt.Print(i," ")
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e8))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(1e5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"sync"
)

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	n := ScanInt()
	m := ScanInt()
	count := 0
	array := make([]bool, m+1)
	for n > 0 {
		n--
		l := ScanInt()
		r := ScanInt()
		for j := l; j <= r; j++ {
			array[j] = true
		}
	}
	//fmt.Println(array)
	outputArray := []int{}
	for i := 1; i <= m; i++ {
		if !array[i]{
			count++
			outputArray = append(outputArray, i)
		}
		//count -= array[i]
		//if 0 == array[i] {
		//
		//}
	}
	fmt.Println(count)
	fmt.Print(SArr(outputArray))

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
	Pl = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e8))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(1e5))
	go func(writer *bufio.Writer) {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ScanWord() string {
	in.Scan()
	return in.Text()
}

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func LCM(a, b int64) int64 {
	return a / GCD(a, b) * b
}

func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}

func S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}

package main

import (
	 "fmt"
)

func main() {
	var a, b int;
 	fmt.Scanf("%d%d", &a, &b)

 	var x = make([]bool, b + 1)
 	for i:=0; i<a; i ++ {
 		  var l, r int;
 		  fmt.Scan(&l)
 		  fmt.Scan(&r)
 		  for j:=l; j<=r; j ++ {
 		  		x[j] = true;
 		  }
 	}

 	var f = make([]int, 0)
 	var ct int
 	for i:=1; i<=b; i ++ {

 		  if(!x[i]) {
 		  	   ct ++;
 		  	   f = append(f, i);
 		  }
 	}
 	fmt.Println(ct)
 	for x := range f {
 		  fmt.Printf("%d ", f[x])
 	}
}

package main

import "fmt"

func main() {
	var n, m, l, r, count int
	fmt.Scan(&n, &m)
	var seg []int = make([]int, m+2)
	for i := 0; i < n; i++ {
		fmt.Scan(&l, &r)
		seg[l] += 1
		seg[r+1] -= 1
	}
	for i := 1; i <= m; i++ {
		seg[i] += seg[i-1]
		if seg[i] == 0 {
			count++
		}
	}
	fmt.Printf("%d\n", count)
	for i := 1; i <= m; i++ {
		if seg[i] == 0 {
			fmt.Printf("%d ", i)
		}
	}
}

package main

import (
    "fmt"
)

func main() {
    var n, k int
    fmt.Scanf("%d%d", &n, &k)
    v := make([]int, k+1)
    for i:=0; i<n; i++ {
        var x, y int
        fmt.Scan(&x)
        fmt.Scan(&y)
        for j:=x; j<=y; j++ {
            v[j] = 1;
        }
    }

    ans := make([]int, 0)
    cnt := 0
    for i:=1; i<=k; i++ {
        if v[i] == 0 {
            cnt++
            ans = append(ans, i)
        }
    }

    fmt.Println(cnt)
    for _, x := range ans {
        fmt.Printf("%d ", x)
    }
}

package main

import "fmt"

var n, m int
var coordinates [128]int

func main() {
	fmt.Scanf("%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		var start, end int
		fmt.Scanf("%d %d\n", &start, &end)
		for j := start; j <= end; j++ {
			coordinates[j] = 1
		}
	}
	var res int
	for i := 1; i <= m; i++ {
		if coordinates[i] == 0 {
			res++
		}
	}
	fmt.Printf("%d\n", res)
	for i := 1; i <= m; i++ {
		if coordinates[i] == 0 {
			fmt.Printf("%d ", i)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type point struct {
	pos   int
	start bool
}

type ByOrder []point

func (a ByOrder) Len() int      { return len(a) }
func (a ByOrder) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByOrder) Less(i, j int) bool {
	if a[i].pos == a[j].pos {
		return a[i].start
	}

	return a[i].pos < a[j].pos
}

type pair struct {
	s, e int
}

func main() {
	var (
		n, m int
	)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())

	scanner.Scan()
	m, _ = strconv.Atoi(scanner.Text())

	points := make([]point, n*2)
	for i := 0; i < n*2; i += 2 {
		scanner.Scan()
		points[i].pos, _ = strconv.Atoi(scanner.Text())
		points[i].start = true

		scanner.Scan()
		points[i+1].pos, _ = strconv.Atoi(scanner.Text())
	}

	sort.Sort(ByOrder(points))

	prev := 1
	var pairs []pair

	depth := 0
	for _, p := range points {
		if p.start {
			if depth == 0 {
				pairs = append(pairs, pair{prev, p.pos - 1})
			}

			depth++
		} else {
			depth--

			if depth == 0 {
				prev = p.pos + 1
			}
		}
	}

	pairs = append(pairs, pair{prev, m})

	// fmt.Println(points)
	// fmt.Println(pairs)

	var res []int
	for _, p := range pairs {
		for i := p.s; i <= p.e; i++ {
			res = append(res, i)
		}
	}

	fmt.Println(len(res))
	for _, v := range res {
		fmt.Print(v, " ")
	}
}

package main

import (
  "fmt"
  "strconv"
  )

func main(){
  var n,m int

  fmt.Scan(&n,&m)
  mt := make([]int,m)
for i:=0;i<n;i++{
    var l,r int
    fmt.Scan(&l,&r)
    for j :=l-1;j<r;j++{
      mt[j] =1
      }
    }
  var r string
  var k int
  for i,t := range mt {
    if t == 0 {
      k++
      r += strconv.Itoa(i+1) + "\n"
      }
    }

    fmt.Println(k,"\n",r)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a, b int
	var asg [101]bool
  var flag bool =true
  ar := [] int {}
  var count int
	fmt.Scanf("%d %d \n", &n, &m)

for i := 1; i <= n; i++ {
		fmt.Scanf("%d %d \n", &a, &b)
		for j := a; j <= b; j++ {
			if asg[j] == false {
				asg[j] = true
			}
		}
	}
for i := 1; i <=m; i++{
  if asg[i] == false {
    flag =false
    count++
    ar =append(ar,i)
  }
}

	if flag == true {
    fmt.Print(0)
  }else {
    fmt.Println(count)
    val := len(ar)
    for i:=0 ; i< val ; i++  {
      fmt.Print(ar[i], " ")
    }
  }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n, m int
	fmt.Fscan(in, &n, &m)

	b := make([]bool, m)
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Fscan(in, &l, &r)
		for j := l - 1; j <= r - 1; j++ {
			b[j] = true
		}
	}

	cnt := 0
	for i := 0; i < m; i++ {
		if !b[i] { cnt++ }
	}

	fmt.Fprintln(out, cnt)
	for i := 0; i < m; i++ {
		if !b[i] {
			fmt.Fprint(out, i + 1, " ")
		}
	}

}

package main

import "fmt"

func main() {
	n, m := 0, 0
	count := 0
	fmt.Scanf("%d %d", &n, &m)
	f := initf(m)
	for i := 0; i < n; i++ {
		l, r := 0, 0
		fmt.Scanf("%d %d", &l, &r)
		for j := l; j <= r; j++ {
			f[j] = true
			count++
		}
	}
	fmt.Println(m - count)
	if count != m {
		flag := false
		for i := 1; i <= m; i++ {
			if !f[i] {
				if flag {
					fmt.Print(" ", i)
				} else {
					fmt.Print(i)
					flag = true
				}
			}
		}
	}
}
func initf(len int) []bool {
	f := make([]bool, len+1)
	for i := 0; i < len+1; i++ {
		f[i] = false
	}
	return f
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	a := make([]int, m+1)
	for i := n; i > 0; i-- {
		var s, e int
		fmt.Scanf("%d %d", &s, &e)
		for j := s; j <= e; j++ {
			a[j] = 1
		}
	}
	ans := make([]int, 0)
	for i := 1; i <= m; i++ {
		if a[i] != 1 {
			ans = append(ans, i)
		}
	}
	fmt.Println(len(ans))
	for _, k := range ans {
		fmt.Printf("%d ", k)
	}
}

package main

import "fmt"

var n, m int
var coordinates [128]int

func main() {
	fmt.Scanf("%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		var start, end int
		fmt.Scanf("%d %d", &start, &end)
		for j := start; j <= end; j++ {
			coordinates[j] = 1
		}
	}
	var res int
	for j := 1; j <= m; j++ {
		if coordinates[j] == 0 {
			res++
		}
	}
	fmt.Printf("%d\n", res)
	for i := 1; i <= m; i++ {
		if coordinates[i] == 0 {
			fmt.Printf("%d ", i)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a, b int
	var asg [101]bool
  var flag bool =true
  ar := [] int {}
  var count int
	fmt.Scanf("%d %d", &n, &m)

for i := 1; i <= n; i++ {
		fmt.Scanf("%d %d", &a, &b)
		for j := a; j <= b; j++ {
			if asg[j] == false {
				asg[j] = true
			}
		}
	}
for i := 1; i <=m; i++{
  if asg[i] == false {
    flag =false
    count++
    ar =append(ar,i)
  }
}

	if flag == true {
    fmt.Print(0)
  }else {
    fmt.Println(count)
    val := len(ar)
    for i:=0 ; i< val ; i++  {
      fmt.Print(ar[i], " ")
    }
  }
}

package main

import "fmt"

func main() {
	n, m := 0, 0
	fmt.Scanf("%d %d", &n, &m)
	f := initf(m)
	for i := 0; i < n; i++ {
		l, r := 0, 0
		fmt.Scanf("%d %d", &l, &r)
		for j := l; j <= r; j++ {
			f[j] = true
		}
	}
	res := processf(f)
	fmt.Println(len(res))
	for i := 0; i < len(res); i++ {
		fmt.Print(res[i], " ")
	}
	if len(res) != 0 {
		fmt.Println()
	}
}
func processf(f []bool) []int {
	var res []int
	for i := 1; i <= len(f)-1; i++ {
		if f[i] == false {
			res = append(res, i)
		}
	}
	return res
}
func initf(len int) []bool {
	f := make([]bool, len+1)
	for i := 0; i < len+1; i++ {
		f[i] = false
	}
	return f
}

package main

import "fmt"

func main() {
	n, m := 0, 0
	fmt.Scanf("%d %d", &n, &m)
	f := initf(m)
	for i := 0; i < n; i++ {
		l,r := 0,0
		fmt.Scanf("%d %d",&l,&r)
		for j:=l;j<=r;j++{
			f[j] = true
		}
	}
	res := processf(f)
	fmt.Println(len(res))
	for i:=0;i<len(res);i++{
		fmt.Print(res[i]," ")
	}
	fmt.Println()
}
func processf(f []bool) []int {
	var res []int
	for i:=1;i<=len(f)-1;i++{
		if f[i]==false{
			res = append(res, i)
		}
	}
	return res
}
func initf(len int) []bool{
	f := make([]bool,len+1)
	for i:=0;i<len+1;i++{
		f[i] = false
	}
	return f
}

package main

import "fmt"

func main() {
	n, m := 0, 0
	fmt.Scanf("%d %d", &n, &m)
	f := initf(m)
	for i := 0; i < n; i++ {
		l, r := 0, 0
		fmt.Scanf("%d %d", &l, &r)
		for j := l; j <= r; j++ {
			f[j] = true
		}
	}
	res := processf(f)
	fmt.Println(len(res))
	for i := 0; i < len(res)-1; i++ {
		fmt.Print(res[i], " ")
	}
	if len(res) != 0 {
		fmt.Println(res[len(res)-1])
	}
}
func processf(f []bool) []int {
	var res []int
	for i := 1; i <= len(f)-1; i++ {
		if f[i] == false {
			res = append(res, i)
		}
	}
	return res
}
func initf(len int) []bool {
	f := make([]bool, len+1)
	for i := 0; i < len+1; i++ {
		f[i] = false
	}
	return f
}

package main

import "fmt"

func main() {
	n, m := 0, 0
	count := 0
	fmt.Scanf("%d %d", &n, &m)
	f := initf(m)
	for i := 0; i < n; i++ {
		l, r := 0, 0
		fmt.Scanf("%d %d", &l, &r)
		for j := l; j <= r; j++ {
			if !f[j] {
				count++
			}
			f[j] = true

		}
	}
	fmt.Println(m - count)
	if count != m {
		flag := false
		for i := 1; i <= m; i++ {
			if !f[i] {
				if flag {
					fmt.Print(" ", i)
				} else {
					fmt.Print(i)
					flag = true
				}
			}
		}
	}
}
func initf(len int) []bool {
	f := make([]bool, len+1)
	for i := 0; i < len+1; i++ {
		f[i] = false
	}
	return f
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		x := make([]bool, n)
		for i := 0; i < m; i++ {
			var a, b, c int
			fmt.Fscan(in, &a, &b, &c)

			x[b-1] = true
		}

		idx := 0
		for i := range x {
			if !x[i] {
				idx = i
				break
			}
		}

		for i := 0; i < n; i++ {
			if i == idx {
				continue
			}

			fmt.Fprintf(out, "%d %d\n", idx+1, i+1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1583B(os.Stdin, os.Stdout)
}

func CF1583B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, m int
		fmt.Fscan(r, &n, &m)
		v := make([]int, n+1)
		for i := 0; i < m ; i++ {
			var a, b, c int
			fmt.Fscan(r, &a, &b, &c)
			v[b] = 1
		}
		for i:= 1; i <= n; i++ {
			if v[i] == 0 {
				for j:=1 ; j <= n; j++ {
					if i != j {
						fmt.Fprintln(w, i, " ", j)
					}
				}
				break
			}
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func CF1583B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n, m int
	var a, b, c int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		f := make([]bool, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &a, &b, &c)
			f[b] = true
		}
		root := 0
		for i := 1; i <= n; i++ {
			if !f[i] {
				root = i
				break
			}
		}
		for i := 1; i <= n; i++ {
			if i != root {
				Fprintf(out, "%d %d\n", i, root)
			}
		}
	}
}

func main() {
	CF1583B(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
const N = 1e5+5;
var vis [N]int;
func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)

	for ;t>0;t-- {
		var n int
		var m int
		fmt.Fscan(in,&n,&m)
		for i:=1;i<=n;i++ {
			vis[i]=0;
		}
		for ;m>0;m-- {
			var(
				a int
				b int
				c int
			)
			fmt.Fscan(in,&a,&b,&c)
			vis[b]=1
		}
		for i:=1;i<=n;i++ {
			if vis[i]==0 {
				for j:=1;j<=n;j++{
					if j==i {
						continue
					}
					fmt.Fprintln(out,i," ",j)
				}
				break
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		z := make([]int, n+1)
		for i := 2; i <= n; i++ {
			z[i] = 1
		}

		for i := 0; i < m; i++ {
			var a, b, c int
			fmt.Fscan(in, &a, &b, &c)

			if z[a] == b && z[b] == c {
				z[b], z[a] = a, c
			} else if z[a] == b {
				z[c] = a
			}
		}

		for i := 2; i <= n; i++ {
			fmt.Fprintf(out, "%d %d\n", z[i], i)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		z := make([]int, n+1)
		for i := 2; i <= n; i++ {
			z[i] = 1
		}

		for i := 0; i < m; i++ {
			var a, b, c int
			fmt.Fscan(in, &a, &b, &c)

			if z[a] == b {
				z[a] = c
			}
		}

		for i := 2; i <= n; i++ {
			fmt.Fprintf(out, "%d %d\n", z[i], i)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		z := make([]int, n+1)
		for i := 2; i <= n; i++ {
			z[i] = 1
		}

		for i := 0; i < m; i++ {
			var a, b, c int
			fmt.Fscan(in, &a, &b, &c)

			if z[c] == b {
				z[c] = a
			}
		}

		for i := 2; i <= n; i++ {
			fmt.Fprintf(out, "%d %d\n", z[i], i)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1583B(os.Stdin, os.Stdout)
}

func CF1583B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, m int
		fmt.Fscan(r, &n, &m)
		v := make([]int, n+1)
		for i := 0; i < m ; i++ {
			var a, b, c int
			fmt.Fscan(r, &a, &b, &c)
			v[b] = 1
		}
		for i:= 1; i <= n; i++ {
			if v[i] == 0 {
				for j:=1 ; j < n; j++ {
					if i != j {
						fmt.Fprintln(w, i, " ", j)
					}
				}
				break
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
const N = 1e5+5;
var vis [N]int;
func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	fmt.Fprintln(out,N)

	for ;t>0;t-- {
		var n int
		var m int
		fmt.Fscan(in,&n,&m)
		for i:=1;i<=n;i++ {
			vis[i]=0;
		}
		for ;m>0;m-- {
			var(
				a int
				b int
				c int
			)
			fmt.Fscan(in,&a,&b,&c)
			vis[b]=1
		}
		for i:=1;i<=n;i++ {
			if vis[i]==0 {
				for j:=1;j<=n;j++{
					if j==i {
						continue
					}
					fmt.Fprintln(out,i," ",j)
				}
				break
			}
		}
	}
}

package main

import(
	"bufio"
	."fmt"
	"io"
	"os"
)
const N = 1e5+5;
var vis [N]int;
func solve(_r io.Reader,_w io.Writer)  {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t int
	Fscan(in,&t)
	Fprintln(out,N)

	for ;t>0;t-- {
		var n int
		var m int
		Fscan(in,&n,&m)
		for i:=1;i<=n;i++ {
			vis[i]=0;
		}
		for ;m>0;m-- {
			var(
				a int
				b int
				c int
			)
			Fscan(in,&a,&b,&c)
			vis[b]=1
		}
		for i:=1;i<=n;i++ {
			if vis[i]==0 {
				for j:=1;j<=n;j++{
					if j==i {
						continue
					}
					Fprintln(out,i," ",j)
				}
				break
			}
		}
	}
}
func main()  {
	solve(os.Stdin,os.Stdout)
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func change(s string) int {
	hour, _ := strconv.Atoi(s[:2])
	minute, _ := strconv.Atoi(s[3:])
	return hour*60+minute
}
func check(i int) bool {
	hour := strconv.Itoa(i / 60)
	minute := strconv.Itoa(i % 60)
	if len(hour) == 1 {
		hour = "0"+hour
	}
	if len(minute) == 1 {
		minute = "0" + minute
	}
	return hour[0] == minute[1] && hour[1] == minute[0]
}

func slove() {
	var s string
	var n int
	fmt.Fscan(r, &s, &n)
	m := change(s)
	cnt := make(map[int]int)
	an := 0
	for  {
		if _,ok := cnt[m] ;ok {
			fmt.Fprintln(w,an)
			return
		}
		cnt[m] = 0
		if check(m) {
			// fmt.Fprintln(w,an)
			an++
			// cnt[m]++
		}
		m = m + n
		m %= 1440

	}

}
func main() {
	defer w.Flush()
	var T int
	fmt.Fscan(r,&T)
	for i := 0; i < T; i++ {
		slove()
	}
}

package main

import (
	"fmt"
)
const true, false = 1, 0

func solve() {
	var hh, mm, s int
	_, err := fmt.Scanf("%d:%d %d\n", &hh, &mm, &s)
	if err != nil {
		return
	}
	preh := hh
	prem := mm
	cnt := 0
	if check(hh, mm) == 1 {
		cnt = cnt + 1
	}
	hh, mm = add(hh, mm, s)
	for hh != preh || mm != prem {
		if check(hh, mm) == 1 {
			cnt = cnt + 1
		}
		hh, mm = add(hh, mm, s)
	}
	fmt.Println(cnt)
}

func add(hh int, mm int, s int) (int, int) {
	mm = mm + s
	more := mm / 60
	mm = mm % 60
	hh = hh + more
	hh = hh % 24
	return hh, mm
}

func check(hh int, mm int) int {
	a := hh / 10
	b := hh % 10
	c := mm / 10
	d := mm % 10
	if a == d && b == c {
		return 1
	}
	return 0
}

func main() {
	var t int
	// 读取数据
	_, err := fmt.Scanln(&t)
	if err != nil {
		return
	}
	for t > 0 {
		solve()
		t--
	}
	// fmt.Println(t)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var h, m, x int
		fmt.Fscanf(in, "%d:%d %d\n", &h, &m, &x)

		ch, cm := h, m
		var tot int
		for {
			d := (ch * 60) + cm + x
			ch = (d / 60) % 24
			cm = d % 60
			if ch/10 == cm%10 && ch%10 == cm/10 {
				tot++
			}
			if ch == h && cm == m {
				break
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var h, m, x int
		fmt.Fscanf(in, "%d:%d %d\n", &h, &m, &x)

		add := func(h, m, x int) (int, int) {
			d := (h * 60) + m + x
			return (d / 60) % 24, d % 60
		}

		ch, cm := h, m
		g := make(map[string]bool)
		var tot int
		for {
			s := fmt.Sprintf("%.2d:%.2d", ch, cm)
			if g[s] {
				break
			}
			g[s] = true
			if s[0] == s[4] && s[1] == s[3] {
				tot++
			}

			ch, cm = add(ch, cm, x)
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func solve() string {
	var time string
	var h, m, ii, hi, mi int
	fmt.Fscan(in, &time)
	fmt.Fscan(in, &ii)
	var tmp int64
	tmp, _ = strconv.ParseInt(strings.Split(time, ":")[0], 10, 32)
	h = int(tmp)

	tmp, _ = strconv.ParseInt(strings.Split(time, ":")[1], 10, 32)
	m = int(tmp)

	hi = ii / 60
	mi = ii % 60

	var res int
	var sh, sm = h, m
	for true {
		m += mi

		if m > 59 {
			h++
			m %= 60
		}
		h += hi
		if h > 23 {
			h %= 24
		}

		if h/10 == m%10 && h%10 == m/10 {
			res++
		}

		if sh == h && sm == m {
			break
		}
	}

	return strconv.FormatInt(int64(res), 10)
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

import "fmt"

func Reverse(s string) string {
    r := []rune(s)
    for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
        r[i], r[j] = r[j], r[i]
    }
    return string(r)
}

type Pair[T, U any] struct {
    First  T
    Second U
}

func main() {
    t := 0;
    fmt.Scanf("%d\n", &t);

    for i := 0; i < t; i++ {
        h, m, x := 0, 0, 0;
        fmt.Scanf("%d:%d %d\n", &h, &m, &x);

        orig := h * 60 + m;

        r := 0;
        for ;; {
            s := fmt.Sprintf("%02d:%02d", h, m);
            if s == Reverse(s) {
                // fmt.Printf("%s %d\n", s, x);
                r++;
            }

            m += x;
            h += m / 60;
            h %= 24;
            m %= 60;
            if orig == h * 60 + m {
                break
            }
        }

        fmt.Printf("%d\n", r);
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	palindromesTime := [...]int{0, 70, 140, 210, 280, 350, 601, 671, 741, 811, 881, 951, 1202, 1272, 1342, 1412}
	in := bufio.NewReader(os.Stdin)
	var t, m, s, d int
	fmt.Fscanf(in, "%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d:%d %d\n", &m, &s, &d)
		ans, currentTime := 0, m*60+s
		timeMap := make(map[int]bool, 128)
		for j := 0; j < 1500; j++ {
			timeMap[currentTime] = true
			currentTime = (currentTime + d) % 1440
		}
		for _, val := range palindromesTime {
			_, ok := timeMap[val]
			if ok {
				ans++
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var a string
		var b int
		fmt.Fscan(r, &a, &b)
		w1 := do(a, b)
		fmt.Fprintln(w, w1)
	}
}

var z = map[int]struct{}{}

func inv(i int) int {
	return (i%10)*10 + i/10
}

func init() {
	for _, v := range [16]int{0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23} {
		z[v*60+inv(v)] = struct{}{}
	}
}

func do(a string, b int) int {
	i := strings.Index(a, ":")
	h, _ := strconv.Atoi(a[:i])
	m, _ := strconv.Atoi(a[i+1:])
	t := h*60 + m
	j := t
	c := 0
	for {
		if _, ok := z[j]; ok {
			c++
		}
		j = (j + b) % (24 * 60)
		if j == t {
			break
		}
	}
	return c
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	palindromeFlags := make([]bool, 1450)

	for h := 0; h < 24; h++ {
		for m := 0; m < 60; m++ {
			d := calculateMinutes(h, m)
			if isPalindrome(timeToString(h, m)) {
				palindromeFlags[d] = true
			}
		}
	}

	var testCases int
	Fscan(in, &testCases)

	for c := 0; c < testCases; c++ {
		var x int
		var startTime string
		Fscan(in, &startTime, &x)

		cnt := 0
		curTime := stringToMinutes(startTime)
		visit := make([]bool, 1450)
		for !visit[curTime] {
			if palindromeFlags[curTime] {
				cnt++
			}
			visit[curTime] = true
			curTime = (curTime + x) % 1440
		}

		Fprintln(out, cnt)

	}
}

func calculateMinutes(h, m int) int {
	return h*60 + m
}

func isPalindrome(s string) bool {
	ss := []rune(s)

	l := 0
	r := len(s) - 1

	for l <= r {
		if ss[l] != ss[r] {
			return false
		}
		l++
		r--
	}
	return true
}

func timeToString(h, m int) string {
	t := ""
	if h < 10 {
		t = Sprintf("0%d", h)
	} else {
		t = Sprintf("%d", h)
	}

	if m < 10 {
		t = Sprintf("%s:0%d", t, m)
	} else {
		t = Sprintf("%s:%d", t, m)
	}
	return t
}

func stringToMinutes(ss string) int {
	parts := strings.Split(ss, ":")
	h, _ := strconv.Atoi(parts[0])
	m, _ := strconv.Atoi(parts[1])

	return h*60 + m
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

/*
1
00:00 1

*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var h, m, x int
	scanf("%d:%d %d\n", &h, &m, &x)

	ch, cm := h, m

	type pair struct {
		h, m int
	}

	pals := make(map[pair]bool)
	if isPal(h, m) {
		pals[pair{h, m}] = true
	}

	cm += x

	for i := 0; i < 5000; i++ {
		ch += cm / 60
		cm = cm % 60

		ch = ch % 24

		if isPal(ch, cm) {
			pals[pair{ch, cm}] = true
		}

		cm += x
	}

	fmt.Fprintln(writer, len(pals))
}

func isPal(h, m int) bool {
	s := fmt.Sprintf("%02d%02d", h, m)

	for i := 0; i < len(s); i++ {
		if s[i] != s[len(s)-1-i] {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func change(s string) int {
	hour, _ := strconv.Atoi(s[:2])
	minute, _ := strconv.Atoi(s[3:])
	return hour*60+minute
}

func reverse(i int) string {
	hour := strconv.Itoa(i / 60)
	minute := strconv.Itoa(i % 60)
	if len(hour) == 1 {
		hour = "0"+hour
	}
	if len(minute) == 1 {
		minute = "0" + minute
	}
	return hour + ":" + minute
}

func check(i int) bool {
	hour := strconv.Itoa(i / 60)
	minute := strconv.Itoa(i % 60)
	if len(hour) == 1 {
		hour = "0"+hour
	}
	if len(minute) == 1 {
		minute = "0" + minute
	}
	return hour[0] == minute[1] && hour[1] == minute[0]
}

func slove() {
	var s string
	var interval int
	fmt.Fscan(r, &s, &interval)
	time := change(s)
	cnt := make(map[int]int)
	ans := 0
	for {
		if _, ok := cnt[time]; ok {
			fmt.Fprintln(w, ans)
			return
		}
		cnt[time] = 0
		if check(time) {
			ans++
		}
		time = time + interval
		time %= 1440
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

var m map[int]bool

func sol() {
	b := myio.ReadBytes()
	// fmt.Println(b)
	i := ri()
	// fmt.Println(i)
	s := (int(b[0]-'0')*10+int(b[1]-'0'))*60 + (int(b[3]-'0')*10 + int(b[4]-'0'))
	c := 0
	t := s
	for {
		if _, ok := m[t]; ok {
			c += 1
		}
		t = (t + i) % 1440
		if t == s {
			break
		}
	}
	myio.Println(c)
}

func pre() {
	m = make(map[int]bool)
	for i := 0; i < 24; i++ {
		a := i / 10
		b := i % 10
		c := a + b*10
		if c < 60 {
			d := i*60 + c
			m[d] = true
		}
	}
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	pre()
	for ; t > 0; t-- {
		// fmt.Println("t=", t)
		sol()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var s string
		var x ,h,m int
		Fscan(in, &s,&x)
		Sscanf(s, "%d:%d",&h,&m)
		t := h*60+m
		vis := map[int]bool{}
		ans := 0
		for !vis[t] {
			vis[t]=true
			s := Sprintf("%02d:%02d",t/60,t%60)
			for i, n := 0, len(s); i < n/2; i++ {
				v, w := s[i], s[n-1-i]
				if v!=w {
					goto o
				}
			}
			ans++
			o:
			t+=x
			if t >= 24*60 {
				t-=24*60
			}
		}
		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const true, false = 1, 0

func solve() {
	var hh, mm, s int
	_, err := fmt.Scanf("%d:%d %d", &hh, &mm, &s)
	if err != nil {
		return
	}
	preh := hh
	prem := mm
	cnt := 0
	if check(hh, mm) == 1 {
		cnt = cnt + 1
	}
	hh, mm = add(hh, mm, s)
	for hh != preh || mm != prem {
		if check(hh, mm) == 1 {
			cnt = cnt + 1
		}
		hh, mm = add(hh, mm, s)
	}
	fmt.Println(cnt)
}

func add(hh int, mm int, s int) (int, int) {
	mm = mm + s
	more := mm / 60
	mm = mm % 60
	hh = hh + more
	hh = hh % 24
	return hh, mm
}

func check(hh int, mm int) int {
	a := hh / 10
	b := hh % 10
	c := mm / 10
	d := mm % 10
	if a == d && b == c {
		return 1
	}
	return 0
}

func main() {
	defer writer.Flush()
	var t int
	// 读取数据
	_, err := fmt.Scan(&t)
	if err != nil {
		return
	}
	for t > 0 {
		solve()
		t--
	}
	// fmt.Println(t)
}

package main

import "fmt"

const true, false = 1, 0

func solve() {
	var hh, mm, s int
	_, err := fmt.Scanf("%d:%d %d", &hh, &mm, &s)
	if err != nil {
		return
	}
	preh := hh
	prem := mm
	cnt := 0
	if check(hh, mm) == 1 {
		cnt = cnt + 1
	}
	hh, mm = add(hh, mm, s)
	for hh != preh || mm != prem {
		if check(hh, mm) == 1 {
			cnt = cnt + 1
		}
		hh, mm = add(hh, mm, s)
	}
	fmt.Println(cnt)
}

func add(hh int, mm int, s int) (int, int) {
	mm = mm + s
	more := mm / 60
	mm = mm % 60
	hh = hh + more
	hh = hh % 24
	return hh, mm
}

func check(hh int, mm int) int {
	a := hh / 10
	b := hh % 10
	c := mm / 10
	d := mm % 10
	if a == d && b == c {
		return 1
	}
	return 0
}

func main() {
	var t int
	// 读取数据
	_, err := fmt.Scan(&t)
	if err != nil {
		return
	}
	for t > 0 {
		solve()
		t--
	}
	// fmt.Println(t)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func solve() string {
	var time string
	var h, m, ii int
	fmt.Fscan(in, &time)
	fmt.Fscan(in, &ii)
	var tmp int64
	tmp, _ = strconv.ParseInt(strings.Split(time, ":")[0], 10, 32)
	h = int(tmp)

	tmp, _ = strconv.ParseInt(strings.Split(time, ":")[1], 10, 32)
	m = int(tmp)

	var res int
	var sh, sm = h, m
	for true {
		m += ii
		if m > 59 {
			m %= 60
			h += 1
			h += ii / 60
			if h > 23 {
				h %= 24
			}
		}
		if h/10 == m%10 && h%10 == m/10 {
			res++
		}
		if sh == h && sm == m {
			break
		}
	}

	return strconv.FormatInt(int64(res), 10)
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}


package main

import (
	"fmt"
	//"sort"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var n int
	flag:=false
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	l:=make([]int,100005)
	r:=make([]int,100005)
	y:=-1
	x:=1000000007
	for i:=1;i<=n;i++ {
		input.Scan()
		aa, _ := strconv.Atoi(input.Text())
		l[i]=aa
		input.Scan()
		bb, _ := strconv.Atoi(input.Text())
		r[i]=bb
		if x>l[i] {
			x=l[i]
		}
		if y<r[i] {
			y=r[i]
		}
	}
	for i:=1;i<=n;i++ {
		if l[i]==x && r[i]==y {
			fmt.Println(i)
			flag=true
			break
		}
	}
	if flag==false {
		fmt.Println(-1)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var totalCoordinate int
	var segments [][]string
	line := -1

	scanner := bufio.NewScanner(os.Stdin)

	var minL int
	var maxR int
	var bestIndex = 0
	for scanner.Scan() {
		line += 1
		if line == 0 {
			totalCoordinate, _ = strconv.Atoi(scanner.Text())
		} else {
			value := strings.Split(scanner.Text(), " ")
			segments = append(segments, value)
			if line == totalCoordinate {
				break
			}
		}
	}

	for i, v := range segments {
		l, _ := strconv.Atoi(v[0])
		r, _ := strconv.Atoi(v[1])
		if i == 0 {
			minL = l
			maxR = r
			continue
		}
		if l <= minL {
			minL = l
		}
		if r >= maxR {
			maxR = r
		}
		if l <= minL && r >= maxR {
			bestIndex = i
			continue
		}
		if bestIndex == 0 && (l < minL || r > maxR) {
			bestIndex = -1
			continue
		}
	}

	var bestSegment []string
	var l, r int
	if bestIndex == -1 {
		fmt.Println(-1)
	} else {
		bestSegment = segments[bestIndex]
		l, _ = strconv.Atoi(bestSegment[0])
		r, _ = strconv.Atoi(bestSegment[1])
		if l == minL && r == maxR {
			fmt.Println(bestIndex + 1)
		} else {
			fmt.Println(-1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var totalCoordinate int
	var segments [][]string
	line := -1

	scanner := bufio.NewScanner(os.Stdin)

	var minL int
	var maxR int
	var bestIndex = 0
	for scanner.Scan() {
		line += 1
		if line == 0 {
			totalCoordinate, _ = strconv.Atoi(scanner.Text())
		} else {
			value := strings.Split(scanner.Text(), " ")
			segments = append(segments, value)
			if line == totalCoordinate {
				break
			}
		}
	}

	for i, v := range segments {
		l, _ := strconv.Atoi(v[0])
		r, _ := strconv.Atoi(v[1])
		if i == 0 {
			minL = l
			maxR = r
			continue
		}
		if l <= minL {
			minL = l
		}
		if r >= maxR {
			maxR = r
		}
		if l <= minL && r >= maxR {
			bestIndex = i
			continue
		}
		if bestIndex == 0 && (l < minL || r > maxR) {
			bestIndex = -1
			continue
		}
	}

	if bestIndex == -1 {
		fmt.Println(-1)
	} else {
		bestSegment := segments[bestIndex]
		l, _ := strconv.Atoi(bestSegment[0])
		r, _ := strconv.Atoi(bestSegment[1])
		if l == minL && r == maxR {
			fmt.Println(bestIndex + 1)
		} else {
			fmt.Println(-1)
		}
	}
}

package main
import(
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
)

func getMinMax(arr [][]string)(int, int){
	min,_ := strconv.Atoi(arr[0][0])
	max := 0
	for i :=0; i < len(arr); i++{
		left,_ := strconv.Atoi(arr[i][0])
		right,_ := strconv.Atoi(arr[i][1])
		if min > left{
			min = left
		}
		if max < right{
			max = right
		}
	}
	return min,max
}

func main(){
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	sum := scanner.Text()
	intsum,_ := strconv.Atoi(sum)
	var arr [][]string
	for i :=0; i < intsum; i++{
		scanner.Scan()
		a := scanner.Text()
		b := strings.Split(a," ")
		arr = append(arr,b)
	}
	min,max := getMinMax(arr)
	linhCanh := 1
	for i := 0; i < intsum; i++{
		left,_ := strconv.Atoi(arr[i][0])
		right,_ := strconv.Atoi(arr[i][1])
		if min == left{
			if max == right{
				fmt.Println(i+1)
				linhCanh = 0
				break
			}
		}
	}
	if linhCanh == 1{
		fmt.Println(-1)
	}

}

package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

type Segment struct {
    l,r int
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    s := make([]Segment,n)
    left, right := 1000000001, 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        s[i].l, _ = strconv.Atoi(scanner.Text())
        scanner.Scan()
        s[i].r, _ = strconv.Atoi(scanner.Text())
        if left > s[i].l { left = s[i].l }
        if right < s[i].r { right = s[i].r }
    }
    ans := -1
    for i := 0; i < n; i++ {
        if (s[i].l == left) && (s[i].r == right) {
            ans = i+1
            break
        }
    }
    fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve(n int, arr [][]int) int {
	min, max := arr[0][0], 0

	for i := range arr {
		if arr[i][0] < min {
			min = arr[i][0]
		}
		if arr[i][1] > max {
			max = arr[i][1]
		}
	}

	for i := range arr {
		if arr[i][0] == min && arr[i][1]== max {
			return i + 1
		}
	}
	return -1
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(r, "%d\n", &n)
	arr := make([][]int, n)

	for i := range arr {
		arr[i] = make([]int, 2)
		fmt.Fscanf(r, "%d %d\n", &arr[i][0], &arr[i][1])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, arr))
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := NewStdReader(os.Stdin)
	n := reader.ReadInt()

	c := -1
	min := 1000000000
	max := 0

	for i := 1; i <= n; i++ {
		L, R := reader.ReadInt(), reader.ReadInt()
		if L <= min && R >= max {
			c = i
			min = L
			max = R
		} else if L < min {
			c = -1
			min = L
		} else if R > max {
			c = -1
			max = R
		}
	}

	fmt.Print(c)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 2*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	var l, r int
	fmt.Fscanf(reader, "%d\n", &n)
	min := math.MaxInt32
	max := math.MinInt32
	c := make(map[int]map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &l, &r)
		if min > l {
			min = l
		}
		if max < r {
			max = r
		}
		m, ok := c[l]
		if ok {
			m[r] = i
		} else {
			c[l] = map[int]int{r: i}
		}
	}
	v, ok := c[min][max]
	if ok {
		fmt.Fprint(os.Stdout, v+1)
	} else {
		fmt.Fprint(os.Stdout, -1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	var l, r int
	fmt.Fscanf(reader, "%d\n", &n)
	min := math.MaxInt32
	max := math.MinInt32
	c := make(map[int]map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &l, &r)
		if min > l {
			min = l
		}
		if max < r {
			max = r
		}
		m, ok := c[l]
		if ok {
			m[r] = i
		} else {
			c[l] = map[int]int{r: i}
		}
	}
	v, ok := c[min][max]
	if ok {
		fmt.Fprint(os.Stdout, v)
	} else {
		fmt.Fprint(os.Stdout, -1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	var l, r int
	fmt.Fscanf(reader, "%d\n", &n)
	min := math.MaxInt32
	max := math.MinInt32
	c := make(map[int]map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &l, &r)
		if min > l {
			min = l
		}
		if max < r {
			max = r
		}
		m, ok := c[l]
		if ok {
			m[r] = i
		} else {
			c[l] = map[int]int{r: i}
		}
	}
	v, ok := c[min][max]
	if ok {
		fmt.Fprint(os.Stdout, -1)
	} else {
		fmt.Fprint(os.Stdout, v)
	}
}

package main

import (
	"fmt"
	//"sort"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var n int
	flag:=false
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	l:=make([]int,n+1)
	r:=make([]int,n+1)
	y:=-1
	x:=10000007
	for i:=1;i<=n;i++ {
		input.Scan()
		aa, _ := strconv.Atoi(input.Text())
		l[i]=aa
		input.Scan()
		bb, _ := strconv.Atoi(input.Text())
		r[i]=bb
		if x>l[i] {
			x=l[i]
		}
		if y<r[i] {
			y=r[i]
		}
	}
	for i:=1;i<=n;i++ {
		if l[i]==x && r[i]==y {
			fmt.Println(i)
			flag=true
			break
		}
	}
	if flag==false {
		fmt.Println(-1)
	}

}

package main

import (
	"fmt"
	//"sort"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var n int
	flag:=false
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	l:=make([]int,n+1)
	r:=make([]int,n+1)
	y:=-1
	x:=100000001
	for i:=1;i<=n;i++ {
		input.Scan()
		aa, _ := strconv.Atoi(input.Text())
		l[i]=aa
		input.Scan()
		bb, _ := strconv.Atoi(input.Text())
		r[i]=bb
		if x>l[i] {
			x=l[i]
		}
		if y<r[i] {
			y=r[i]
		}
	}
	for i:=1;i<=n;i++ {
		if l[i]==x && r[i]==y {
			fmt.Println(i)
			flag=true
			break
		}
	}
	if flag==false {
		fmt.Println(-1)
	}

}

package main

import (
	"fmt"
	//"sort"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var n int
	flag:=false
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
	fmt.Scan(&n)
	l:=make([]int,n+1)
	r:=make([]int,n+1)
	y:=-1
	x:=100000007
	for i:=1;i<=n;i++ {
		input.Scan()
		aa, _ := strconv.Atoi(input.Text())
		l[i]=aa
		input.Scan()
		bb, _ := strconv.Atoi(input.Text())
		r[i]=bb
		if x>l[i] {
			x=l[i]
		}
		if y<r[i] {
			y=r[i]
		}
	}
	for i:=1;i<=n;i++ {
		if l[i]==x && r[i]==y {
			fmt.Println(i)
			flag=true
			break
		}
	}
	if flag==false {
		fmt.Println(-1)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var totalCoordinate int
	var segments [][]string
	line := -1

	scanner := bufio.NewScanner(os.Stdin)

	var bestResult [2]int
	var bestIndex = 0
	for scanner.Scan() {
		line += 1
		if line == 0 {
			totalCoordinate, _ = strconv.Atoi(scanner.Text())
		} else {
			value := strings.Split(scanner.Text(), " ")
			segments = append(segments, value)
			if line == totalCoordinate {
				break
			}
		}
	}

	for i, v := range segments {
		l, _ := strconv.Atoi(v[0])
		r, _ := strconv.Atoi(v[1])
		if i == 0 {
			bestResult[0] = l
			bestResult[1] = r
			continue
		}
		if l <= bestResult[0] && r >= bestResult[1] {
			bestResult[0] = l
			bestResult[1] = r
			bestIndex = i
			continue
		}
		if bestIndex == 0 && (l > bestResult[0] || r < bestResult[1]) {
			bestIndex = -1
			continue
		}
	}

	if bestIndex == -1 {
		fmt.Println(-1)
	} else {
		fmt.Println(bestIndex + 1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var totalCoordinate int
	var segments [][]string
	line := -1

	scanner := bufio.NewScanner(os.Stdin)

	var minL int
	var maxR int
	var bestIndex = 0
	for scanner.Scan() {
		line += 1
		if line == 0 {
			totalCoordinate, _ = strconv.Atoi(scanner.Text())
		} else {
			value := strings.Split(scanner.Text(), " ")
			segments = append(segments, value)
			if line == totalCoordinate {
				break
			}
		}
	}

	for i, v := range segments {
		l, _ := strconv.Atoi(v[0])
		r, _ := strconv.Atoi(v[1])
		if i == 0 {
			minL = l
			maxR = r
			continue
		}
		if l <= minL {
			minL = l
		}
		if r >= maxR {
			maxR = r
		}
		if l <= minL && r >= maxR {
			bestIndex = i
			continue
		}
		if bestIndex == 0 && (l < minL || r > maxR) {
			bestIndex = -1
			continue
		}
	}

	if bestIndex == 0 {
		segmentZero := segments[0]
		l, _ := strconv.Atoi(segmentZero[0])
		r, _ := strconv.Atoi(segmentZero[1])
		if l == minL && r == maxR {
			fmt.Println(0)
		} else {
			fmt.Println(-1)
		}
	} else {
		if bestIndex == -1 {
			fmt.Println(-1)
		} else {
			fmt.Println(bestIndex + 1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var totalCoordinate int
	var segments [][]string
	line := -1

	scanner := bufio.NewScanner(os.Stdin)

	var minL int
	var maxR int
	var bestIndex = 0
	for scanner.Scan() {
		line += 1
		if line == 0 {
			totalCoordinate, _ = strconv.Atoi(scanner.Text())
		} else {
			value := strings.Split(scanner.Text(), " ")
			segments = append(segments, value)
			if line == totalCoordinate {
				break
			}
		}
	}

	for i, v := range segments {
		l, _ := strconv.Atoi(v[0])
		r, _ := strconv.Atoi(v[1])
		if i == 0 {
			minL = l
			maxR = r
			continue
		}
		if l <= minL {
			minL = l
		}
		if r >= maxR {
			maxR = r
		}
		if l <= minL && r >= maxR {
			bestIndex = i
			continue
		}
		if bestIndex == 0 && (l < minL || r > maxR) {
			bestIndex = -1
			continue
		}
	}

	if bestIndex == 0 {
		segmentZero := segments[0]
		l, _ := strconv.Atoi(segmentZero[0])
		r, _ := strconv.Atoi(segmentZero[1])
		if l == minL && r == maxR {
			fmt.Println(1)
		} else {
			fmt.Println(-1)
		}
	} else {
		if bestIndex == -1 {
			fmt.Println(-1)
		} else {
			fmt.Println(bestIndex + 1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var totalCoordinate int
	var segments [][]string
	line := -1

	scanner := bufio.NewScanner(os.Stdin)

	var minL int
	var maxR int
	var bestIndex = 0
	for scanner.Scan() {
		line += 1
		if line == 0 {
			totalCoordinate, _ = strconv.Atoi(scanner.Text())
		} else {
			value := strings.Split(scanner.Text(), " ")
			segments = append(segments, value)
			if line == totalCoordinate {
				break
			}
		}
	}

	for i, v := range segments {
		l, _ := strconv.Atoi(v[0])
		r, _ := strconv.Atoi(v[1])
		if i == 0 {
			minL = l
			maxR = r
			continue
		}
		if l <= minL {
			minL = l
		}
		if r >= maxR {
			maxR = r
		}
		if l <= minL && r >= maxR {
			bestIndex = i
			continue
		}
		if bestIndex == 0 && (l < minL || r > maxR) {
			bestIndex = -1
			continue
		}
	}

	if bestIndex == -1 {
		fmt.Println(-1)
	} else {
		fmt.Println(bestIndex + 1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	var totalCoordinate int
	var segments [][]string
	line := -1

	scanner := bufio.NewScanner(os.Stdin)

	var bestResult [2]int
	var bestIndex = 0
	for scanner.Scan() {
		line += 1
		if line == 0 {
			totalCoordinate, _ = strconv.Atoi(scanner.Text())
		} else {
			value := strings.Split(scanner.Text(), " ")
			segments = append(segments, value)
			if line == totalCoordinate {
				break
			}
		}
	}

	for i, v := range segments {
		l, _ := strconv.Atoi(v[0])
		r, _ := strconv.Atoi(v[1])
		if i == 0 {
			bestResult[0] = l
			bestResult[1] = r
			continue
		}
		if l <= bestResult[0] && r >= bestResult[1] {
			bestResult[0] = l
			bestResult[1] = r
			bestIndex = i
			continue
		}
		if bestIndex == 0 && (l < bestResult[0] || r > bestResult[1]) {
			bestIndex = -1
			continue
		}
	}

	if bestIndex == -1 {
		fmt.Println(-1)
	} else {
		fmt.Println(bestIndex + 1)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 100010
var n int
var x int

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &n)
	var tot = 0
	var cur = 0

	var workers = make([]int, N)
	var from = make([]int, 0)
	var to = make([]int, 0)

	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &x)

		if x > cur {
			tot += x - cur
			// new
			for j := 0; j < x - cur; j++ {
				from = append(from, i)
				to = append(to, 0) // not end yet
				workers[cur + j] = len(from) - 1
			}
		} else {
			// remove
			var out = cur - x

			for j := 0; j < out; j++ {
				to[workers[cur - 1 - j]] = i - 1
			}
		}
		cur = x
	}

	for i := 0; i < len(from); i++ {
		if to[i] == 0 {
			to[i] = n
		}
	}

	fmt.Fprintf(writer, "%d\n", tot)

	for i := 0; i < tot; i++{
		fmt.Fprintf(writer, "%d %d\n", from[i], to[i])
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/174/problem/C

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Call struct {
	L int
	R int
}

func Solve(n int, a []int) []Call {
	left := []int{}
	calls := []Call{}
	for i := 1; i <= n+1; i++ {
		for j := 0; j < a[i]-a[i-1]; j++ {
			left = append(left, i)
		}
		for j := 0; j < a[i-1]-a[i]; j++ {
			calls = append(calls, Call{L: left[len(left)-1], R: i - 1})
			left = left[:len(left)-1]
		}
	}
	return calls
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n+2)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}

	calls := Solve(n, a)
	fmt.Fprintf(writer, "%d\n", len(calls))
	for i := 0; i < len(calls); i++ {
		fmt.Fprintf(writer, "%d %d\n", calls[i].L, calls[i].R)
	}
}