import sys
input = sys.stdin.readline


n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = [-1] * n
tmp = 0

for i in range(m):
    if ans[sc[i][0] - 1] == -1:
        ans[sc[i][0] - 1] = sc[i][1]
    elif ans[sc[i][0] - 1] != sc[i][1]:
        tmp = 1

for j in range(n):
    if ans[j] == -1:
        ans[j]=0

if (tmp==1) | (ans[0]==0):
    print(-1)
else:
    print(*ans, sep='')
