N,Q = map(int, input().split())
l = [[int(i) for i in input().split()] for Q in range(Q)]
 
base = [0] * N
flag = False
for i in l:
    if i[1] == 0 and i[0]-1 == 0:
        flag = True
        break
    elif base[i[0]-1] == 0:
        base[i[0]-1] = i[1]
    elif base[i[0]-1] == i[1]:
        pass
    elif base[i[0]-1] != i[1]:
        flag = True
        break
 
if flag == True:
    print(-1)
elif N == 1 and base[0] == 0:
    print(0)
elif base[0] == 0:
    base[0] = 1
    a = map(lambda x: str(x), base)
    print(''.join(a))
else:
    a = map(lambda x: str(x), base)
    print(''.join(a))