n,m = map(int,input().split())
c = [[], [], [] ,[], [], []]
for i in range(m):
    s,x = map(int,input().split())
    c[s].append(x)

r = 0
d = [-1 for _ in range(n)]

for i in range(len(c)):
    if i == 0 or i > n:
        if len(c[i]) != 0:
            r = -1
            break
    elif len(set(c[i])) > 1:
        r = -1
        break
    elif len(set(c[i])) == 0:
        continue
    elif i == 1 and c[i][0] == 0:
        r = -1
        break
    else:
        d[i-1] = c[i][0]

if r == -1:
    print(r)
else:
    if n == 3:
        if d[0] == -1:
            d[0] = 1
        if d[1] == -1:
            d[1] = 0
        if d[2] == -1:
            d[2] = 0
    elif n == 2:
        if d[0] == -1:
            d[0] = 1
        if d[1] == -1:
            d[0] = 0
    else:
        if d[0] == -1:
            d[0] = 0
    print(''.join(map(str,d)))