import std.stdio : readln, writeln;
import std.array : split;
import std.conv : to;
import std.typecons;
import std.algorithm : map;
import std.range : iota;
import std.string : chomp;

char[Tuple!(int, int)] field;
int W, H;

void main() {
  auto input = map!(to!int)(split(chomp(readln()))[0 .. 2]);
  W = input[0], H = input[1];
  
  foreach (int y; iota(H))
    foreach (int x, char v; readln()[0 .. W])
      field[tuple(x, y)] = v;

  int res = 0;
  while (1) {
    auto end = map!(to!int)(split(chomp(readln()))[0 .. 2]);
    if (end[0] == 0 && end[1] == 0) break;
  }
  writeln(res);
  return 0;
}