#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    S = []
    for i in range(m):
        x,y = readInts()
        x -=1
        S.append((x,y))
    for i in range(10**n):
        s = str(i)
        if len(S) != n:
            continue
        if all(S[a] == str(b) for a,b in S):
            print(i)
            exit()
    print(-1)
    """for i in range(n):
        S.append(0)
    La = False
    for i in range(m):
        s,c = readInts()
        s -=1
        if S[s] == 0 or S[s] == c:
            S[s] = c
            La = True
        else:
            print('-1')
            exit()
    if La:
        if n == 3 and S[0] == 0:
            print('-1')
            exit()
        if n == 2 and S[0] == 0:
            print('-1')
            exit()
    if S.count(0) == n and not n == 1: # もし0の数が桁数と一緒ならば、
        S[0] = 1
    print(*S,sep='')
    """
if __name__ == '__main__':
  main()
