import sys
import math
import copy
import queue
input = sys.stdin.readline
n,m = map(int,input().split())
ans = list('-' * n)
for _ in range(m):
    s,c = input().split()
    i = int(s) - 1
    if ans[i] == '-' or ans[i] == c:
        ans[i] = c
    else:
        print(-1)
        exit (0)

if ans[0] == '0' and ans != '0':
    print (-1)
else:
    print (''.join(ans).replace('-','0'))