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

ans = ['' for _ in range(N)]

for _ in range(M):
    s, c = map(str, input().split())
    if (ans[int(s)-1] != '') and (ans[int(s)-1] != c):
        print("-1")
        break
    else:
        ans[int(s)-1] = c
else:
    ans = ['0' if s == '' else s for s in ans]
    if (N > 1) and(M == 0):
        ans[0] = '1'
    if (N > 1) and (ans[0] == '0'):
        print("-1")
    else:
        print(''.join(ans))