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