n, m = map(int,input().split())
lst = []
for _ in range(m):
    lst.append(list(map(int,input().split())))

number = [[] for _ in range(n)]
for v in lst:
    keta,num = v[0]-1,v[1]
    if not number[keta]:
        number[keta] = num
    else:
        if number[keta] != num:
            print(-1)
            exit()

if number[0] == 0:
    print(-1)
    exit()

if not number[0]:
    number[0] = [1]

for i in range(m):
    if not number[i]:
        number[i] = 0

print(''.join([str(i) for i in number]))