import java.util.*

fun main(args:Array<String>?): Unit {
    val (w, h) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(h){readLine()!!.trim().toCharArray()}
    val goal = (0 until w).mapNotNull { x -> (0 until h).find{y -> state[y][x] == 't'}?.let{y -> Point(x, y)} }.first()
    val isReach = Array(h){BooleanArray(w){false}}
    val queue: Queue<Point> = ArrayDeque<Point>()
    repeat(readLine()!!.trim().toInt() + 1) {
        if (it == 0) {
            isReach[0][0] = true
            queue.add(Point(0, 0))
        }else {
            val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
            state[y][x] = '.'
            if (Point(x, y).neighbors.any{p -> (p.x in 0 until w) && (p.y in 0 until h) && isReach[p.y][p.x]}) {
                isReach[y][x] = true
                queue.add(Point(x, y))
            }
        }
        while(queue.isNotEmpty()){
            for ((x, y) in queue.poll().neighbors)
                if (x in 0 until w && y in 0 until h && state[y][x] != '#' && !isReach[y][x]) {
                    isReach[y][x] = true
                    queue.add(Point(x, y))
                }
        }
        //println(isReach.joinToString("\n", postfix = "\n"){it.joinToString(","){if (it) "o" else "x"}})
        if (isReach[goal.y][goal.x]) {
            println(it)
            return
        }
    }
    println(-1)
}
data class Point(val x: Int, val y: Int) {
    operator fun plus(that: Point): Point = Point(x + that.x, y + that.y)
}
val Point.neighbors: Iterable<Point>
    get() = listOf(Point(1, 0), Point(-1, 0), Point(0, 1), Point(0, -1)).map{it + this}
