n, m = map(int, input().split())
lst = [[0]*2 for i in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    lst[i][0] = a
    lst[i][1] = b

ans = 1000
for i in range(10**(n-1), 10**n):
    str_num = str(i)
    flag = True
    for l in lst:
        if str_num[l[0]-1] != str(l[1]):
            flag = False
    if flag == True and i < ans:
        ans = i


print(ans if ans!=1000 else '-1')