n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
s.sort()
num = [0]*n
flag = False
num[s[0][0]-1] = s[0][1]
for i in range(1, m):
    if s[i-1][0] == s[i][0] and s[i-1][1] != s[i][1]:
        flag = True
        break
    if s[i][0] == 1 and s[i][1] == 0:
        flag = True
        break
    num[s[i][0]-1] = s[i][1]
if num[0] == 0:
    num[0] = 1
if flag == True:
    print(-1)
else:
    tmp = ''.join(list(map(str, num)))
    if tmp == str(int(tmp)):
        print(tmp)
    else:
        print(-1)