#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
INF = float('inf')
N, M=map(int, input().split())
num=['0' for i in range(N)]
res = True

for i in range(M):
    s,c=map(int, input().split())

    if num[s-1] == '0':
        num[s-1] = str(c)
    else:
        if num[s-1] != str(c):
            res = False
            break

if res:
    min_num = ''.join(num)
    if  int(min_num) > 0:
        print(min_num)
    else:
        print(-1)
else:
    print(-1)
