#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9 + 7;
constexpr ll MOD1 = 998244353;
ll dp[2010][2010];
void solve() {
  int n, m;
  cin >> n >> m;
  int s[n], t[m];
  for (int i = (0); i < (n); i++) {
    cin >> s[i];
  }
  for (int i = (0); i < (m); i++) {
    cin >> t[i];
  }
  for (int i = 0; i <= n; i++) {
    dp[0][i] = 1;
    dp[i][0] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      dp[i + 1][j + 1] %= MOD;
      dp[i + 1][j + 1] *= (s[i] == t[j] ? 2 : 1);
      dp[i + 1][j + 1] %= MOD;
    }
  }
  cout << dp[n][m] << endl;
}
int main(int argc, char *argv[]) {
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  for (int case_no = (0); case_no < (case_num); case_no++) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }
  return 0;
}
