N,M = map(int,input().split())
ls_1 = []
ls_2 = []
ls_3 = []
for i in range(M):
    s,c = map(int,input().split())
    if s == 1:
        ls_1.append(c)
    elif s == 2:
        ls_2.append(c)
    else:
        ls_3.append(c)
if len(set(ls_1)) > 1 or len(set(ls_2)) > 1 or len(set(ls_3)) > 1 or ls_1[0] == 0:
    print(-1)
else:
    if len(ls_1) == 0:
        if N > 1:
            ls_1.append(1)
        else:
            ls_1.append(0)
    if len(ls_2) == 0:
        ls_2.append(0)
    if len(ls_3) == 0:
        ls_3.append(0)
    
    ans = (10 **(N-1)) * ls_1[0] + (10**((N-2)*(N-1)// 2)) * ls_2[0] + ((N-2)*(N-1) // 2) * ls_3[0]
    print(ans)