N, M = map(int,input().split())
SC = [-1]*(N+1)
ans = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if SC[s] != -1 and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c
flg = 1
for i in range(10**(N-1),10**N):
    s = str(i)
    for j in range(1,N+1):
        if SC[j] == -1:
            continue
        if SC[j] != int(s[j-1]):
            flg = 0
            break
    if not flg:
        flg = 1
        continue
    if flg:
        print(i)
        exit()
print(-1)