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

dic = {}
for m in range(M):
    s, c = map(int, input().split())
    if s not in dic:
        dic[s] = c
    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':
    print(-1)
else:
    print(''.join(word))
