#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  cin >> m;
  vector<int> s;
  vector<int> t;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    s.push_back(x);
  }
  for (int j = 0; j < m; j++) {
    cin >> x;
    t.push_back(x);
  }
  int dp[2002][2002];
  int con[2002][2002];
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) {
      dp[i][j] = 0;
      con[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (int i = 1; i < n + 1; i++) {
    dp[i][0] = 1;
    if (s[i - 1] == t[0]) {
      dp[i][1] = 2;
    }
  }
  for (int j = 1; j < m + 1; j++) {
    dp[0][j] = 1;
    if (t[j - 1] == s[0]) {
      dp[1][j] = 2;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        con[i][j] = 1;
      }
    }
  }
  for (int x = 1; x < n + 1; x++) {
    for (int y = 1; y < m + 1; y++) {
      int tmp = 0;
      for (int k = 0; k < y - 1; k++) {
        if (con[x - 1][k] > 0) {
          tmp += dp[x - 1][k];
          tmp %= 1000000007;
        }
      }
      for (int l = 0; l < x - 1; l++) {
        if (con[l][y - 1] > 0) {
          tmp += dp[l][y - 1];
          tmp %= 1000000007;
        }
      }
      tmp = tmp + dp[x - 1][y - 1];
      tmp %= 1000000007;
      if (con[x - 1][y - 1] > 0) {
        tmp += dp[x - 1][y - 1];
        tmp %= 1000000007;
      }
      dp[x][y] = tmp;
    }
  }
  cout << dp[n][m];
  return 0;
}
