#!/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:
    head_zero = True
    ret_str = ''
    for n in num:
        if head_zero:
            if n != '0':
                head_zero = False
                ret_str += n
        else:
            ret_str += n
    if  ret_str != '' and int(ret_str) > 0:
        print(ret_str)
    else:
        print(-1)
else:
    print(-1)
