import math
def main():
    N, M = map(int, input().split())

    ans = {i:0 for i in range(N)}

    for _ in range(M):
        s, c = map(int, input().split())
        if s-1 not in ans:
            print(-1)
            return 0
        if (ans[s-1] != 0) and (ans[s-1] > c):
            ans[s-1] = c
        else:
            ans[s - 1] = c
    if (ans[0] == 0) and (len(ans) != 1):
        print(-1)
        return 0

    for v in ans.values():
        print(v, end="")




    return 0
if __name__ == '__main__':
    main()