#include <bits/stdc++.h>
using namespace std;
int64_t dp[2001][2001] = {0};
static const int64_t kRem = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> ss(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> ss[i];
  }
  vector<int> ts(m + 1);
  for (int i = 1; i <= m; i++) {
    cin >> ts[i];
  }
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 1;
  }
  for (int j = 0; j <= m; j++) {
    dp[0][j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int64_t val = 0;
      if (ss[i] != ts[j]) {
        val = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      } else {
        val = dp[i - 1][j] + dp[i][j - 1];
      }
      dp[i][j] = val % kRem;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
