N, M = map(int, input().split())

A = []
bit = []
for i in range(N):
    A.append(9)
    bit.append(0)
# print(A)

ans = "0"

for j in range(M):
    s, c = map(int, input().split())
    if ans == "-1":
        continue
    if bit[s-1]==1 and A[s-1] != c:
        ans = "-1"
        continue
    elif bit[s-1]==1 and A[s-1] == c:
        continue
    ans = "0"
    A[s-1] = min(c, A[s-1])
    bit[s-1] = 1

# print(A)
# print(ans)

for k in range(N):
    if bit[k]==0:
        A[k]=0
            
if ans != "-1" and A[0] != 0:
#     print(A)
#     for k in range(N):
#         if bit[k]==0:
#             A[k]=0

    print(int("".join(map(str,A))))
else:
    print("-1")