#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (auto&& e : s) cin >> e;
  for (auto&& e : t) cin >> e;
  long long dp[3000][3000] = {};
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      bool eq = s[i] == t[j];
      if (i == 0 || j == 0) {
        if (i)
          if (eq)
            dp[i][j] = dp[i - 1][j] + 1;
          else
            dp[i][j] = dp[i - 1][j];
        dp[i][j] %= 1000000007;
        if (j)
          if (eq)
            dp[i][j] = dp[i][j - 1] + 1;
          else
            dp[i][j] = dp[i][j - 1];
        dp[i][j] %= 1000000007;
        if (i == 0 && j == 0)
          if (eq) dp[i][j] = 1;
        dp[i][j] %= 1000000007;
        continue;
      }
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
      if (eq) dp[i][j] += (dp[i - 1][j - 1] + 1);
      dp[i][j] %= 1000000007;
    }
  }
  cout << (dp[n - 1][m - 1] + 1) % 1000000007 << endl;
  return 0;
}
