#!/usr/bin/env python3

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


d = {}
for i in range(M):
    s, c = map(int, input().split())
    if s in d:
        if d[s] == c:
            continue
        else:
            print(-1)
            exit()
    else:
        d[s] = c



start = 0
end = 0
if N == 1:
    start=1
    end = 10
elif N == 2:
    start = 10
    end = 100
else:
    start = 100
    end = 1000
index = start
ans = -1
while index < end-2:
    f = True
    for s, c in d.items():
        str_index = str(index)
        if str_index[s-1] != str(c):
            index += 1
            f = False
            break

    if f == True:
        ans = index
        break
    
    
print(ans)
