#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}
void _cout() { cout << "\n"; }
template <class Head, class... Tail>
void _cout(Head&& head, Tail&&... tail) {
  cout << head;
  _cout(forward<Tail>(tail)...);
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
constexpr int MOD = 1e9 + 7;
int main(void) {
  int n, m;
  _cin(n, m);
  vector<int> s(n);
  for (int i = 0; i < (n); i++) cin >> s[i];
  vector<int> t(m);
  for (int i = 0; i < (m); i++) cin >> t[i];
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
  for (int i = 0; i < (n + 1); i++) dp[i][0] = 1;
  for (int j = 0; j < (m + 1); j++) dp[0][j] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]);
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]);
      }
      dp[i][j] %= MOD;
    }
  _cout(dp[n][m]);
}
