# -*- coding: utf-8 -*-
import sys

[N, M] = [int(i) for i in input().split()]

SC = []
for m in range(M):
    [s, c] = [int(i) for i in input().split()]
    SC.append((s, c))

ans_str = ['0'] * N

print(ans_str)

for (s, c) in SC:
    if ans_str[s - 1] != '0' and ans_str[s - 1] != str(c):
        print(-1)
        sys.exit()
        
    ans_str[s - 1] = str(c)

print(ans_str)

for s in ans_str:
    if s != '0':
        break
else:
    print(-1)
    sys.exit()

for i in range(len(ans_str)):
    if ans_str[i] == '0':
        ans_str[i] = '1'
    else:
        break

ans = ''.join(ans_str)
print(int(ans))