n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int,input().split())))
sc = sorted(sc, key=lambda x:x[0])
#print(sc)
ans = [0] * (n+1)
lis = [-1] * (n+1)
for i in range(m):
    if lis[sc[i][0]] == -1:
        lis[sc[i][0]] = sc[i][1]
    if lis[sc[i][0]] != -1 and lis[sc[i][0]] != sc[i][1]:
        print('-1')
        exit()
    if sc[i][0] == 1 and sc[i][1] == 0 and n > 1:
        print('-1')
        exit()
for i in range(m):
    ans[sc[i][0]] = sc[i][1]
del ans[0]
if ans[0] == 0:
    ans[0] = 1
print(''.join(map(str, ans)))