from bisect import bisect_left from itertools import pairwise import sys sys.setrecursionlimit(2000000) class UnionFindTree: def __init__(self, length: int, values: list[int], value_mod: int) -> None: self.list = [idx for idx in range(length)] self.size = [1 for _ in range(length)] self.value = [value for value in values] self.mod = value_mod def get_root(self, idx: int) -> int: if self.list[idx] == idx: return idx self.list[idx] = self.get_root(self.list[idx]) return self.list[idx] def is_same(self, idx1: int, idx2: int) -> bool: return self.get_root(idx1) == self.get_root(idx2) def merge(self, idx1: int, idx2: int): if self.is_same(idx1, idx2): return idx1_root = self.get_root(idx1) idx2_root = self.get_root(idx2) if self.size[idx1_root] > self.size[idx2_root]: self.list[idx2_root] = idx1_root self.size[idx1_root] += self.size[idx2_root] self.value[idx1_root] += self.value[idx2_root] self.value[idx1_root] %= self.mod else: self.list[idx1_root] = idx2_root self.size[idx2_root] += self.size[idx1_root] self.value[idx2_root] += self.value[idx1_root] self.value[idx2_root] %= self.mod def get_size(self, idx: int) -> int: return self.size[self.get_root(idx)] def get_value(self, idx: int) -> int: return self.value[self.get_root(idx)] % self.mod def main(): MOD = 998244353 N, M = map(int, input().split()) A = list(map(int, input().split())) uft = UnionFindTree(N, A, MOD) for _ in range(M): U, V = map(lambda n: int(n) - 1, input().split()) uft.merge(U, V) ans = 1 for node in range(N): ans *= uft.get_value(node) ans %= MOD print(ans) if __name__ == "__main__": main()