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