#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL << 60;
const ll M = 1000000007;
int main() {
  ll n, m;
  cin >> n >> m;
  vll S(n), T(m);
  for (ll i = 0; i < n; i++) {
    cin >> S[i];
  }
  for (ll i = 0; i < m; i++) {
    cin >> T[i];
  }
  vvll dp(2002, vll(2002));
  dp[0][0] = 1;
  if (S[0] == T[0]) {
    dp[1][1] = 2;
  } else {
    dp[1][1] = 1;
  }
  for (ll i = 1; i < 2002; i++) {
    dp[0][i] = 1;
  }
  for (ll i = 1; i < 2002; i++) {
    dp[i][0] = 1;
  }
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = 1; j < m + 1; j++) {
      if (i == 1 && j == 1) {
        continue;
      }
      if (S[i - 1] == T[j - 1]) {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
        dp[i][j] %= M;
      } else {
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
        dp[i][j] %= M;
      }
    }
  }
  cout << (dp[n][m] % M) << "\n";
}
