from collections import defaultdict

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

def main():
    N,M=mis()
    nlis=[0]*N
    num=defaultdict(set)
    for _ in range(M):
        a,b=mis()
        if N>1 and a==N and b==0:no()
        num[a].add(b)
    for i in range(1,N+1):
        if len(num[i])>1: no()
        elif num[i]: nlis[i-1]=num[i].pop()
    if N>1 and nlis[N-1]==0:nlis[N-1]=1

    print(int(''.join([str(n) for n in nlis])))
    

def no():
    print(-1)
    exit()


if __name__ == "__main__":
    main()