#include <bits/stdc++.h>
using namespace std;
char matrix[500][500];
bool vis[500][500];
int n, m;
string word;
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
bool valid(int x, int y, int w) {
  if (x >= 0 && x < n && y >= 0 && y < m && matrix[x][y] == word[w])
    return 1;
  else
    return 0;
}
int solve(int x, int y, int w) {
  vis[x][y] = true;
  if (w == word.size() - 1) {
    return 1;
  }
  int sol = 0;
  for (int i = 0; i < 8; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (valid(nx, ny, w + 1) && !vis[nx][ny]) {
      sol += solve(nx, ny, w + 1);
    }
  }
  vis[x][y] = false;
  return sol;
}
int main() {
  cin >> n >> m;
  cin >> word;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> matrix[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (matrix[i][j] == word[0]) {
        memset(vis, 0, sizeof vis);
        ans += solve(i, j, 0);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
