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