#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const long long MOD = 1e9 + 7;
int n, m;
long long dp[N][N];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (auto& i : a) cin >> i;
  for (auto& i : b) cin >> i;
  for (int i = 0; i < (N); ++i) {
    dp[0][i] = 1;
    dp[i][0] = 1;
  }
  for (int i = 1; i < (n + 1); ++i) {
    for (int j = 1; j < (m + 1); ++j) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = (2 * dp[i - 1][j - 1]) +
                   (dp[i - 1][j] + dp[i][j - 1] - 2 * dp[i - 1][j - 1]);
        dp[i][j] %= MOD;
      } 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];
}
