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

for i in range(m):
    s, c = map(int, input().split())
    # 先頭が0のとき
    if s == 1 and c == 0:
        print(-1)
        exit()
    
    if keta[s-1] >= 0:
        if keta[s-1] != c:
            print(-1)
            exit()
        else: keta[s-1] = c
    else: keta[s-1] = c

ans = ''
for i in keta:
    if i == -1: ans += '0'
    else: ans += str(i)
print(int(ans))