#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (auto &e : s) cin >> e;
  for (auto &e : t) cin >> e;
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  for (int i = 0; i <= n; i++) dp[i][0] = 1;
  for (int i = 0; i <= m; i++) dp[0][i] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int num = t[j];
      dp[i + 1][j + 1] = dp[i + 1][j];
      for (int k = i; k >= 0; k--) {
        if (s[k] == num) {
          dp[i + 1][j + 1] += dp[k][j];
          dp[i + 1][j + 1] %= int(1e9 + 7);
        }
      }
    }
  }
  cout << dp[n][m] % int(1e9 + 7) << endl;
}
