N,M =map(int,input().split()) str =input() pdca ={l:list() for l in ["PD","DC","CA"]} for i in range(M): s,t =map(int,input().split()) str2 =str[s-1]+str[t-1] if str2 =="PD": pdca["PD"].append([s,t]) elif str2 =="DP": pdca["PD"].append([t,s]) elif str2 =="DC": pdca["DC"].append([s,t]) elif str2 =="CD": pdca["DC"].append([t,s]) elif str2 =="CA": pdca["CA"].append([s,t]) elif str2 =="AC": pdca["CA"].append([t,s]) sum = 0 dclist =[0]*N calist =[0]*N for lis in pdca["CA"]: calist[lis[0]-1] += 1 for lis in pdca["DC"]: dclist[lis[0]-1] += calist[lis[1]-1] for lis in pdca["PD"]: sum += dclist[lis[1]-1] print(sum)