#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(const T& x) {
  cout << setprecision(12) << x << endl;
}
template <class T, class... A>
void print(const T& first, const A&... rest) {
  cout << first << " ";
  print(rest...);
}
struct PreMain {
  PreMain() {
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
} premain;
int N, M;
int S[(2001)];
int T[(2001)];
long long dp[(2001)][(2001)];
long long dp_cumsum[(2001)][(2001)];
int main() {
  cin >> N >> M;
  for (int(i) = 0; (i) < (int)(N); ++(i)) {
    cin >> S[i];
  }
  for (int(j) = 0; (j) < (int)(M); ++(j)) {
    cin >> T[j];
  }
  for (int(i) = 0; (i) < (int)(N); ++(i)) {
    for (int(j) = 0; (j) < (int)(M); ++(j)) {
      if (S[i] == T[j]) {
        dp[i][j] = 1;
        if ((0 < i) && (0 < j)) {
          dp[i][j] += dp_cumsum[i - 1][j - 1];
          dp[i][j] %= (1000000007);
        }
      } else {
        dp[i][j] = 0;
      }
      dp_cumsum[i][j] = dp[i][j];
      if (0 < i) {
        dp_cumsum[i][j] += dp_cumsum[i - 1][j];
        dp_cumsum[i][j] %= (1000000007);
      }
      if (0 < j) {
        dp_cumsum[i][j] += dp_cumsum[i][j - 1];
        dp_cumsum[i][j] %= (1000000007);
      }
      if ((0 < i) && (0 < j)) {
        dp_cumsum[i][j] -= dp_cumsum[i - 1][j - 1];
        dp_cumsum[i][j] %= (1000000007);
      }
    }
  }
  print(dp_cumsum[N - 1][M - 1] + 1);
  return 0;
}
