from collections import deque MOD = 998244353 N, M = map(int, input().split()) A = list(map(int, input().split())) edges = [[] for i in range(N)] for i in range(M): u, v = map(lambda x: x - 1, map(int, input().split())) edges[u].append(v) edges[v].append(u) ans = 1 done = [0] * N for i in range(N): if done[i]: continue done[i] = 1 dq = deque([i]) c = 1 s = A[i] while dq: now = dq.popleft() for nxt in edges[now]: if done[nxt]: continue done[nxt] = 1 dq.append(nxt) c += 1 s += A[nxt] s %= MOD ans *= pow(s, c, MOD) ans %= MOD print(ans)