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

num = [-1]
for _ in range(N - 1):
	num += [-1]

for _ in range(M):
  s, c = list(map(int, input().split()))
  if num[s - 1] != -1 and num[s - 1] != c:
    print('-1')
    exit()
  num[s - 1] = c

if num[0] == -1:
  num[0] = 1

print(''.join(map(str, map(lambda x: 0 if x == -1 else x, num))))