#include <bits/stdc++.h>
using namespace std;
long long int dp[2020][2020];
long long int ac[2001][100001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int(i) = 0; (i) < (2020); (i)++)
    for (int(j) = 0; (j) < (2020); (j)++) dp[i][j] = 0;
  for (int(i) = 0; (i) < (n + 1); (i)++) dp[i][0] = 1;
  for (int(i) = 0; (i) < (m + 1); (i)++) dp[0][i] = 1;
  vector<long long int> s(n), t(m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  for (int i = 1; i < n + 1; i++)
    for (int j = 0; j < 100001; j++) ac[i][j] = 0;
  for (int j = 0; j < 100001; j++) ac[0][j] = 0;
  for (int j = 1; j <= m; j++) {
    for (int i = 0; i <= n; i++)
      ac[i][t[j - 1]] = (ac[i][t[j - 1]] + dp[i][j - 1]) % 1000000007;
    ;
    for (int i = 1; i <= n; i++) {
      long long int sum = 0;
      sum = (sum + ac[i - 1][s[i - 1]]) % 1000000007;
      ;
      dp[i][j] = (dp[i - 1][j] + sum) % 1000000007;
      ;
    }
  }
  for (int(i) = 0; (i) < (n + 1); (i)++) {
  }
  cout << dp[n][m] << endl;
  return 0;
}
