#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " ";
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl;
  return os;
}
template <typename T>
inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  cin >> s >> t;
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i > 0) dp[i][j] += dp[i - 1][j];
      if (j > 0) dp[i][j] += dp[i][j - 1];
      if (i > 0 && j > 0 && s[i - 1] != t[j - 1]) {
        dp[i][j] -= dp[i - 1][j - 1];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
