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

if N == 1 and M == 0:
    print(0)
    sys.exit()

dic = {}
for m in range(M):
    s, c = map(int, input().split())
    if s not in dic.keys():
        dic[s] = c
    else:
        if s == 1 and c == 0:
            continue
        else:
            dic[s] = min(dic[s], c)
word = ['0'] * N
for key, value in dic.items():
    word[key - 1] = str(value)
if word[0] == '0' and len(word) > 1:
    print(-1)
else:
    print(''.join(word))
