#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(n):
        S.append(0)
    for i in range(m):
        s,c = readInts()
        s -=1
        if S[s] == 0 or S[s] == c:
            S[s] = c
        else:
            print('-1')
            exit()
    l_ = 0
    for i in range(n-1):
        if S[i] == 0:
            l_ += 1
        else:
            break
    ANS = S[l_:]
    if n == len(S) - l_:
        print(*ANS,sep='')
    else:
        print('-1')
if __name__ == '__main__':
  main()
