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

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

for i in range(n):
    if len(set(c[i])) > 1:
        r = -1
        break
    elif len(c[i]) == 0:
        continue
    else:
        d[i] = 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[1] = 0
    else:
        if d[0] == -1:
            d[0] = 0
    print(''.join(map(str,d)))