FLOOR = "."
WALL = "#"
BAG = "t"
NEXT = [
  [0, 1],
  [0, -1],
  [1, 0],
  [-1, 0],
]
H, W = gets.split.map(&:to_i)
STORE = H.times.map{gets.chomp.chars}
START = [0, 0]
GOAL = [STORE.find_index{|y| y.include?(BAG)}, STORE.transpose.find_index{|x| x.include?(BAG)}]

class DisjointSet
  def initialize
    @parent = Hash.new
    @rank = Hash.new
  end
  def make(node)
    @parent[node] = node
    @rank[node] = 0
  end
  def union(node1, node2)
    link(find(node1), find(node2))
  end
  def link(node1, node2)
    node1, node2 = node2, node1 if @rank[node1] < @rank[node2]
    @parent[node2] = node1
    @rank[node1] += 1 if @rank[node1] == @rank[node2]
  end
  def find(node)
    (@parent[node] == node) ? node : (@parent[node] = find(@parent[node]))
  end
end

set = DisjointSet.new
H.times do |y|
  W.times do |x|
    set.make([y, x]) unless STORE[y][x] == WALL
  end
end
H.times do |y|
  W.times do |x|
    next if STORE[y][x] == WALL
    NEXT.each do |(dy, dx)|
      ny = y + dy
      nx = x + dx
      next unless (0...H).include?(ny)
      next unless (0...W).include?(nx)
      next if STORE[ny][nx] == WALL
      set.union([y, x], [ny, nx])
    end
  end
end

s = (set.find(START) == set.find(GOAL)) ? 0 : -1
(1..gets.to_i).each do |i|
  x, y = gets.split.map(&:to_i)
  set.make([y, x])
  NEXT.each do |(dy, dx)|
    ny = y + dy
    nx = x + dx
    next unless s == -1
    next unless (0...H).include?(ny)
    next unless (0...W).include?(nx)
    next if STORE[ny][nx] == WALL
    set.union([y, x], [ny, nx])
    s = i if set.find(START) == set.find(GOAL)
  end
end
p s