import scipy J=lambda:map(int,input().split()) print(scipy.stats.kendalltau(*map(list,zip(*[J()for _ in[0]*sum(J())])))[0])