import collections as cl
N, M = map(int, input().split())
dic = cl.defaultdict(lambda:-1)
num = 0
for i in range(0, M):
    s, c = map(int, input().split())
    if N - s in dic and dic[N-s] != c:
        print(-1)
        exit(0)
    else:
        dic[N-s] = c
if dic[N-1] == -1:
    dic[N-1] = 1
for j in dic.keys():
    num += dic[j] * (10 ** j)
if num < 10 ** (N - 1):
    print(-1)
else:
    print(num)