← Home
```go
package main

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

type Page struct {
	num   int
	words []string
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	
	line, _ := reader.ReadString('\n')
	line = strings.TrimSpace(line)
	nk := strings.Split(line, " ")
	n, _ := strconv.Atoi(nk[0])
	k, _ := strconv.Atoi(nk[1])
	
	pages := make([]Page, n)
	
	for i := 0; i < n; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		p, _ := strconv.Atoi(line)
		pages[i] = Page{num: p, words: make([]string, k)}
		for j := 0; j < k; j++ {
			line, _ = reader.ReadString('\n')
			pages[i].words[j] = strings.TrimSpace(line)
		}
	}
	
	sort.Slice(pages, func(i, j int) bool {
		return pages[i].num < pages[j].num
	})
	
	allWords := make([]string, 0, n*k)
	for _, p := range pages {
		allWords = append(allWords, p.words...)
	}
	
	chars := make(map[byte]struct{})
	for _, w := range allWords {
		for i := 0; i < len(w); i++ {
			chars[w[i]] = struct{}{}
		}
	}
	
	adj := make(map[byte]map[byte]bool)
	inDegree := make(map[byte]int)
	for c := range chars {
		inDegree[c] = 0
	}
	
	for i := 0; i < len(allWords)-1; i++ {
		w1, w2 := allWords[i], allWords[i+1]
		minLen := len(w1)
		if len(w2) < minLen {
			minLen = len(w2)
		}
		found := false
		for j := 0; j < minLen; j++ {
			if w1[j] != w2[j] {
				c1, c2 := w1[j], w2[j]
				if adj[c1] == nil {
					adj[c1] = make(map[byte]bool)
				}
				if !adj[c1][c2] {
					adj[c1][c2] = true
					inDegree[c2]++
				}
				found = true
				break
			}
		}
		if !found && len(w1) > len(w2) {
			fmt.Println("IMPOSSIBLE")
			return
		}
	}
	
	queue := make([]byte, 0)
	for c, d := range inDegree {
		if d == 0 {
			queue = append(queue, c)
		}
	}
	
	result := make([]byte, 0, len(chars))
	for len(queue) > 0 {
		c := queue[0]
		queue = queue[1:]
		result = append(result, c)
		for nb := range adj[c] {
			inDegree[nb]--
			if inDegree[nb] == 0 {
				queue = append(queue, nb)
			}
		}
	}
	
	if len(result) != len(chars) {
		fmt.Println("IMPOSSIBLE")
		return
	}
	
	fmt.Println(string(result))
}
```