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

l = [0 for _ in range(N)]

# set
in_list = [set() for _ in range(N)]
for _ in range(M):
    s, c = list(map(int, input().split()))
    in_list[s-1].add(c)


flg = True
zero_flg = False
res = -1
for i, item in enumerate(in_list):
    if i == 0 and len(item) == 0:
        res = 1 * 10**(N-1)
        zero_flg = True
        continue
    if len(item) >= 2:
        flg = False
    if len(item) == 0:
        continue
    
    n = item.pop()
    if n > 0:
        zero_flg = True
    if not zero_flg and i < N-1:
        flg = False
        break
    res = max(0, res)
    res += n * 10 ** (N-(i+1))
    
if not flg :
    print(-1)
else:
    print(res)