from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,m=mis()
    flag=0
    dic=defaultdict(list)
    for i in range(m):
        s,c=mis()
        if c not in dic[s]:
            dic[s].append(c)
    if n>1 and dic[1]==0: flag=1
    for i in range(1,n+1):
        if len(dic[i])>1: flag=1
    if flag: 
        print(-1)
        exit()
    for i in range(1,n+1):
        if len(dic[i])>0:
            print(dic[i][0],end='')
        else: print(0,end='')
    print()



if __name__ == "__main__":
    main()