N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    """if s == 1 and c == 0:
        print(-1)
        exit()"""
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

z = zip(S, C)
z = sorted(z)
S, C = zip(*z)

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]-1] = C[i]

if ans[0] == 0:
    print(-1)
    exit()

if ans[0] == -1 and ans[1] == 0:
    print(-1)
    exit()

if ans[0] == -1 and ans[1] == -1 and ans[2] == -1:
    print(-1)
    exit()
if ans[0] == -1 and ans[1] == -1:
    print(ans[2])
    exit()
if ans[0] == -1:
    print(str(ans[1]) + str(max(0, ans[2])))
    exit()
print(str(ans[0]) + str(max(0, ans[1])) + str(max(0, ans[2])))