n, m, *s_c = map(int, open(0).read().split())

num = [0] * n
cnt = [0] * n
flag = 1
for i in range(m):
    if cnt[s_c[2*i] - 1] > 0 and s_c[2*i + 1] != num[s_c[2*i] - 1]:
        flag = -1
        break
    else:
        num[s_c[2*i] - 1] = s_c[2*i + 1]
        
if num[0] == 0:
    flag = -1

if flag == -1:
    print(-1)
else:
    print(''.join(map(str, num)))