def main():
    N, M = (int(i) for i in input().split())
    from collections import defaultdict
    dic = defaultdict(set)
    for i in range(M):
        s, c = (int(i) for i in input().split())
        dic[s].add(c)
    for i in range(1, N+1):
        if len(dic[i]) > 1:
            return print(-1)
        elif not(dic[i]):
            dic[i].add(0)
    s = ""
    for i in range(1, N+1)[::-1]:
        s = s + str(dic[i].pop())
    print(s if int(s) != 0 else -1)


if __name__ == '__main__':
    main()
