import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 3); int w = Integer.parseInt(first[0]); int h = Integer.parseInt(first[1]); int[][] ver = new int[h + 1][w + 1]; int[][] hor = new int[h + 1][w + 1]; int n = Integer.parseInt(first[2]); for (int i = 0; i < n; i++) { int m = Integer.parseInt(br.readLine()); String[] line = br.readLine().split(" ", m + 1); int prev = Integer.parseInt(line[0]); for (int j = 0; j < m; j++) { int x = Integer.parseInt(line[j + 1]); int min = Math.min(prev, x); int max = Math.max(prev, x); if (max - min >= w) { ver[min / w][min % w]++; ver[max / w + 1][max % w]--; } else { hor[min / w][min % w]++; hor[max / w][max % w + 1]--; } prev = x; } } for (int i = 0; i < h; i++) { for (int j = 1; j < w; j++) { hor[i][j] += hor[i][j - 1]; } } for (int i = 0; i < w; i++) { for (int j = 1; j < h; j++) { ver[j][i] += ver[j - 1][i]; } } PriorityQueue queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); int[][] costs = new int[h][w]; for (int[] arr : costs) { Arrays.fill(arr, Integer.MAX_VALUE); } while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.r][p.c] <= p.value) { continue; } costs[p.r][p.c] = p.value; if (p.r > 0 && ver[p.r][p.c] > 0 && ver[p.r - 1][p.c] > 0 && costs[p.r - 1][p.c] == Integer.MAX_VALUE) { queue.add(new Path(p.r - 1, p.c, p.value + 1)); } if (p.r < h - 1 && ver[p.r][p.c] > 0 && ver[p.r + 1][p.c] > 0 && costs[p.r + 1][p.c] == Integer.MAX_VALUE) { queue.add(new Path(p.r + 1, p.c, p.value + 1)); } if (p.c > 0 && hor[p.r][p.c] > 0 && hor[p.r][p.c - 1] > 0 && costs[p.r][p.c - 1] == Integer.MAX_VALUE) { queue.add(new Path(p.r, p.c - 1, p.value + 1)); } if (p.c < w - 1 && hor[p.r][p.c] > 0 && hor[p.r][p.c + 1] > 0 && costs[p.r][p.c + 1] == Integer.MAX_VALUE) { queue.add(new Path(p.r, p.c + 1, p.value + 1)); } } if (costs[h - 1][w - 1] == Integer.MAX_VALUE) { System.out.println("Odekakedekinai.."); } else { System.out.println(costs[h - 1][w - 1]); } } static class Path implements Comparable { int r; int c; int value; public Path(int r, int c, int value) { this.r = r; this.c = c; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }