n, m = map(int, input().split())
sc = [map(int, input().split()) for i in range(m)]
s, c = [list(i) for i in zip(*sc)]

for i in range (10**(n-1),10**n):
    p = str(i)
    flag = 0
    for j in range(m):
        if p[s[j]-1] != str(c[j]):
            flag = 1
            break

    if flag == 0:
        print(i)
        flag = 2
        break

if flag != 2:
    print("-1")