n, m = map(int, input().split())
num = [-1 for _ in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    if not num[s-1] == -1 and not num[s-1] == c:
        print(-1)
        exit()
    num[s-1] = c
if not all(num) and num[0] == "0" or num[0] == -1:
    print(-1)
    exit()
if (num[0] == "0" or num[0] == -1) and not n == 1:
     print(-1)
     exit()
if num[0] == -1:
    print(-1)
    exit()
for i in range(n):
    if not num[i] == "0":
        continue
    print(-1)
    exit()
for i in range(n):
    if not num[i] == -1:
        print(num[i], end="")
    else:
        print(0, end="")
print("")
