#include<bits/stdc++.h>
#define pb           push_back
#define mp           make_pair
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define PI 3.14159265 /// tan inverse = atan(value)*(180/PI)

#define ms(a,b)            memset(a, b, sizeof(a))
#define lp(i,a,b) for (int i = a; i <= b; i++)
#define pii                pair <int,int>

#define SL(a)              scanf("%I64d",&a)
#define SLL(a,b)           scanf("%I64d %I64d",&a,&b)
#define PL(x) printf("%I64d\n",(x))
#define PLL(x,y) printf("%I64d %I64d\n",x,y)

#define S(a)              scanf("%d",&a)
#define SS(a,b)           scanf("%d %d",&a,&b)
#define P(x) printf("%d\n",(x))
#define PP(x,y) printf("%d %d\n",x,y)
using namespace std ;
typedef long long ll ;
const int imin = 1e9+100;
const ll maxx = 3e5+10,mod=1e9+7,imax=1e18+10;
ll dp[maxx];
map < ll ,ll > pq ;
int main()
{
   ll n,p=0,ans=0;
   cin >> n ;
   for(int i=1;i<=n;i++)
   {
       ll x ;
       cin >> x ;
       if(i%2==1){x=-x;}
       p+=x;
       ans+=(pq[p]);
       if(p==0){ans++;}
       pq[p]++;
   }
   cout << ans << endl;
   return 0 ;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long ll;

typedef pair<int, int> P;
struct edge { int to, cost; };

const int MAX_V =3000000;
const int INF = 1<<30;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    rep(i, M) cin >> A[i] >> B[i];
    int K;
    cin >> K;
    vector<int> C(K);
    rep(i, K) cin >> C[i];
    V = N;
    rep(i, M) {
        G[A[i] - 1].push_back({B[i] - 1, 1});
        G[B[i] - 1].push_back({A[i] - 1, 1});
    }
    vector<vector<ll>> d2(K, vector<ll>(K));
    rep(i, K) {
        dijkstra(C[i] - 1);
        rep(j, K) {
            d2[i][j] = d[C[j] - 1];
            //cout << d2[i][j] << " ";
        }
        //cout << "\n";
    }
    V = 1 + K * (1 << K) + 1;
    rep(i, V) G[i] = {};
    rep(i, K) {
        G[0].push_back({1 + (1 << i) * K + i, 0});
        G[V - i - 2].push_back({V - 1, 0});
    }
    rep(i, (1 << K) - 1) {
        rep(j, K) {
            rep(k, K) {
                if (i & (1 << k)) continue;
                G[1 + i * K + j].push_back({1 + (i | (1 << k)) * K + k, d2[j][k]});
            }
        }
    }
    dijkstra(0);
    ll ans = d[V - 1] + 1;
    if (ans == INF + 1) ans = -1;
    cout << ans << "\n";
}