#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(long long int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void print_YES_NO(bool answer) { cout << (answer ? "YES" : "NO") << endl; }
void print_Yes_No(bool answer) { cout << (answer ? "Yes" : "No") << endl; }
void print_POSSIBLE_IMPOSSIBLE(bool answer) {
  cout << (answer ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}
long long int dp[2005][2005];
int t[2][200005];
int main() {
  int n, m;
  long long int a, b, c;
  int i, j, k;
  long long int s = 1;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> t[0][i];
  }
  for (i = 0; i < m; i++) {
    cin >> t[1][i];
  }
  dp[0][0] = 1;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) {
      if (i + j == 0) continue;
      if (i == 0) {
        dp[i][j] = dp[i][j - 1];
        continue;
      }
      if (j == 0) {
        dp[i][j] = dp[i - 1][j];
        continue;
      }
      dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      if (dp[i][j] >= MAX) dp[i][j] %= MAX;
      if (t[0][i - 1] == t[1][j - 1]) dp[i][j] += dp[i - 1][j - 1];
      if (dp[i][j] >= MAX) dp[i][j] %= MAX;
    }
  }
  cout << dp[n][m] % MAX << endl;
}
