def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n, m = map(int,input().split())
    a = [list(map(int,input().split())) for i in range(m)]
    ans = [0]*n
    flg = [0]*n
    for i in range(m):
        idx = a[i][0]-1
        if flg[idx] == 0:
            flg[idx] = 1
            ans[idx] = a[i][1]
        elif ans[idx] == a[i][1]:
            continue
        else:
            print(-1)
            return
    if n > 1 and ans[0] == 0:
        print(-1)
        return
    print(*ans, sep="")

if __name__ == '__main__':
    main()
