#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (int i = 0; i < (int)(n); i++) {
    cin >> s[i];
  }
  for (int i = 0; i < (int)(m); i++) {
    cin >> t[i];
  }
  if (n == 1) {
    long long cnt = 0;
    for (int i = 0; i < (int)(m); i++) {
      if (s[0] == t[i]) {
        cnt++;
      }
    }
    cout << cnt << endl;
    return 0;
  }
  if (m == 1) {
    long long cnt = 0;
    for (int i = 0; i < (int)(n); i++) {
      if (s[i] == t[0]) {
        cnt++;
      }
    }
    cout << cnt << endl;
    return 0;
  }
  vector<vector<long long>> dp(n, vector<long long>(m));
  if (s[0] == t[0])
    dp[0][0] = 2;
  else
    dp[0][0] = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] == t[0])
      dp[i][0] = dp[i - 1][0] + 1;
    else
      dp[i][0] = dp[i - 1][0];
  }
  for (int j = 1; j < m; j++) {
    if (s[0] == t[j])
      dp[0][j] = dp[0][j - 1] + 1;
    else
      dp[0][j] = dp[0][j - 1];
  }
  vector<vector<int>> al(n);
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (s[i] == t[j]) al[i].push_back(j);
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      dp[i][j] = dp[i - 1][j];
      for (int k = 0; k < (int)(al[i].size()); k++) {
        int l = al[i][k];
        if (l == 0) {
          dp[i][j] = (dp[i][j] + 1) % (1000000007);
          continue;
        }
        if (l > j) break;
        dp[i][j] = (dp[i][j] + dp[i - 1][l - 1]) % (1000000007);
      }
    }
  }
  cout << dp[n - 1][m - 1] << endl;
  return 0;
}
