#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, m; scanf("%d%d", &n, &m); std::vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	for(int i = 0; i < m; i++) scanf("%d", &b[i]);
	
	const int MOD = 1e9 + 7;
	
	std::vector<i64> s(m + 1, 1); s[0] = 0;
	auto dp = make_v<i64>(n + 1, m + 1); dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(a[i] == b[j]) (dp[i + 1][j + 1] += s[j + 1]) %= MOD;
		}
		i64 tmp = 0;
		for(int j = 0; j <= m; j++) {
			(s[j] += tmp) %= MOD;
			(tmp += dp[i + 1][j]) %= MOD;
		}
	}
	
	i64 ans = 0;
	for(auto v: dp) for(auto w: v) (ans += w) %= MOD;
	printf("%lld\n", ans);
	return 0;
}
