#include <bits/stdc++.h>
using namespace std;
static long long MOD = 1e9 + 7;
class ECommonSubsequence {
 public:
  void solve(std::istream &in, std::ostream &out) {
    int n, m;
    in >> n >> m;
    vector<int> u(n), v(m);
    for (int i = 0; i < (int)(n); ++i) in >> u[i];
    for (int i = 0; i < (int)(m); ++i) in >> v[i];
    vector<vector<int> > dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 0; i < (int)(n + 1); ++i) dp[i][0] = 1;
    for (int i = 0; i < (int)(m + 1); ++i) dp[0][i] = 1;
    for (int i = (int)(1); i <= (int)(n); ++i)
      for (int j = (int)(1); j <= (int)(m); ++j) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        if (u[i - 1] != v[j - 1]) dp[i][j] = dp[i][j] - dp[i - 1][j - 1] + MOD;
        dp[i][j] %= MOD;
      }
    out << dp[n][m] << endl;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ECommonSubsequence solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
