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 * w]; int[] hor = new int[h * w]; 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]++; ver[max]--; } else { hor[min]++; hor[max]--; } prev = x; } } for (int i = 0; i < h; i++) { for (int j = 1; j < w; j++) { hor[i * w + j] += hor[i * w + j - 1]; } } for (int i = 0; i < w; i++) { for (int j = 1; j < h; j++) { ver[j * w + i] += ver[(j - 1) * w + i]; } } PriorityQueue queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); int[] costs = new int[h * w]; Arrays.fill(costs, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; if (p.idx / w > 0 && ver[p.idx - w] > 0 && costs[p.idx - w] == Integer.MAX_VALUE) { queue.add(new Path(p.idx - w, p.value + 1)); } if (ver[p.idx] > 0 && costs[p.idx + w] == Integer.MAX_VALUE) { queue.add(new Path(p.idx + w, p.value + 1)); } if (p.idx % w > 0 && hor[p.idx - 1] > 0 && costs[p.idx - 1] == Integer.MAX_VALUE) { queue.add(new Path(p.idx - 1, p.value + 1)); } if (hor[p.idx] > 0 && costs[p.idx + 1] == Integer.MAX_VALUE) { queue.add(new Path(p.idx + 1, p.value + 1)); } } if (costs[h * w - 1] == Integer.MAX_VALUE) { System.out.println("Odekakedekinai.."); } else { System.out.println(costs[h * w - 1]); } } static class Path implements Comparable { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }