import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    sc = [[] for _ in range(n)]
    num = str()
    for _ in range(m):
        s, c = map(int, input().split())
        sc[s-1] += [c]
    if n > 1 and 0 in sc[0]:
        sc[0].pop(sc[0].index(0))
    for i in range(n):
        if sc[i] == []:
            num += '0'
        else:
            num += str(min(sc[i]))
    if len(list(str(int(num)))) != n:
        print(-1)
    else:
        print(int(num))
    

if __name__ == '__main__':
    main()