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

sc.sort(key=lambda x: x[0])

num = [0]*n
check = [False] * n
for i in range(m):
    if check[sc[i][0]-1] and num[sc[i][0]-1] != sc[i][1]:
        print(-1)
        quit()
    if num[sc[i][0]-1] == 0:
        num[sc[i][0]-1] = sc[i][1]
        check[sc[i][0]-1] = True
ans = ''
for i in range(n):
    ans += str(num[i])

if ans[0] != '0':
    print(ans)
else:
    print(-1)