# -*- 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 = ['-1'] * N

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

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

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