#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
  o << "]";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "{" << p.first << ", " << p.second << "}";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
  o << "{";
  for (auto itr = obj.begin(); itr != obj.end(); ++itr)
    o << (itr != obj.begin() ? ", " : "") << *itr;
  o << "}";
  return o;
}
long long MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, x;
  cin >> n >> m;
  vector<int> s, t;
  vector<vector<long long>> cnt(n, vector<long long>(m, 0)),
      sum(n, vector<long long>(m, 0));
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 1));
  for (int i = 0; i < n; i++) {
    cin >> x;
    s.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    t.push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] * 2 + (dp[i - 1][j] - dp[i - 1][j - 1]) +
                   (dp[i][j - 1] - dp[i - 1][j - 1]);
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
