import sys


N, M = map(int, input().split())
ans = [0 for _ in range(N)]
status = [0 for _ in range(N)]
for _ in range(M):
    s, c = map(int, input().split())
    if s > N:
        print('-1')
        sys.exit()

    if status[s-1] == 0:
        ans[s-1] = c 
        status[s-1] = 1
    elif status[s-1] == 1 and ans[s-1] != c:
        print('-1')
        sys.exit()

checked_ans = ans.copy()
flg = False
for i, a in enumerate(ans):
    if a == 0:
        checked_ans.pop(0)
        continue
    else:
        flg = True
        break
    
if flg == False:
    print('0')
    sys.exit()
checked_ans = ''.join([str(a) for a in checked_ans])
print(checked_ans)

