N, M = map(int, input().split())
li = [-1]*N
flag = True
for i in range(M):
    s, c = map(int, input().split())
    if li[N-s] < 0 or li[N-s] == c:
        li[N-s] = c
    else:
        flag = False
if not flag:
    print(-1)
else:
    if N == 1:
        print(li[0])
    else:
        if li[N-1] == 0:
            print(-1)
        else:
            cnt = 0
            for i in range(N-1):
                if li[i] >= 0:
                    cnt += li[i] * 10 ** i
            if li[N-1] < 0:
                cnt += 10 ** (N-1)
            else:
                cnt += li[N-1] * 10 ** (N-1)
            print(cnt)