#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
const int64_t MOD = 1000000000 + 7;
int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  std::vector<int64_t> s, t;
  for (int i = 0; i < n; i++) {
    int m1;
    cin >> m1;
    s.push_back(m1);
  }
  for (int i = 0; i < m; i++) {
    int m1;
    cin >> m1;
    t.push_back(m1);
  }
  int64_t dp[21][21] = {};
  int64_t cum[21][21] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        if (i == 0 || j == 0) {
          dp[i][j] = 1;
        } else {
          dp[i][j] = 1 + cum[i - 1][j - 1];
        }
      } else {
        dp[i][j] = 0;
      }
      if (i == 0 && j == 0) {
        cum[i][j] = dp[i][j];
      } else if (i == 0) {
        cum[i][j] = dp[i][j] + cum[i][j - 1];
      } else if (j == 0) {
        cum[i][j] = dp[i][j] + cum[i - 1][j];
      } else {
        cum[i][j] =
            cum[i][j - 1] + cum[i - 1][j] - cum[i - 1][j - 1] + dp[i][j];
      }
      assert(dp[i][j] < INT64_MAX && 0 <= dp[i][j]);
      assert(cum[i][j] < INT64_MAX && 0 <= cum[i][j]);
      dp[i][j] %= MOD;
      cum[i][j] %= MOD;
    }
  }
  int64_t result = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      result += dp[i][j];
      result %= MOD;
    }
  }
  assert(result < MOD && 0 <= result);
  cout << result << endl;
  return 0;
}
