def guess_number(n, s_c):
    s_c.sort()
    for i in range(len(s_c)-1):
        if s_c[i][0] == s_c[i+1][0] and s_c[i][1] != s_c[i+1][1]:
            return -1

    ans = []
    ans.append(1)
    if n > 1:
        for i in range(n-1):
            ans.append(0)

    for v in s_c:
        if v[0] == 1 and v[1] == 0:
            return -1
        ans[v[0]-1] = v[1]
    return int("".join([str(i) for i in ans]))

s_c = []
n, m = [int(i) for i in input().split()]
for j in range(m):
    s_c.append([int(i) for i in input().split()])

print(guess_number(n, s_c))