#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T>
ostream& prnt(ostream& out, T v) {
  out << v.size() << '\n';
  for (auto e : v) out << e << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T> v) {
  return prnt(out, v);
}
template <class T>
ostream& operator<<(ostream& out, set<T> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, map<T1, T2> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  return out << '(' << p.first << ' ' << p.second << ')';
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
const long long N = 2010;
const long long MOD = 1e9 + 7;
long long n, s[N], t[N], dp[N][N], ans, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> s[i];
  for (long long i = 1; i <= m; i++) cin >> t[i];
  dp[0][0] = 1;
  for (long long i = 1; i < N; i++) dp[i][0] = dp[0][i] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = (s[i] == t[j]) * (dp[i - 1][j - 1]);
      dp[i][j] += dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  cout << dp[n][m];
}
