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