n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(m)]

lst = [[-1] for _ in range(n)]

for i in sc:
    lst[i[0] -1].append(i[1])

ans = ''

for i in lst:
    if len(set(i)) == 2:
        ans += str(i[1])
    elif len(set(i)) == 1:
        ans += '0'
    else:
        print(-1)
        exit()

if ans[0] != '0':
    print(ans)
else:
    print(-1)