# -*- coding: utf-8 -*-

def main():
    N, M = map(int, input().split())
    d = {}
    for _ in range(M):
        s, c = map(int, input().split())
        if s > N:
            print("-1")
            return
        if s in d:
            if d[s] != c:
                print("-1")
                return
        else:
            d[s] = c

    result = ""
    for i in range(1, M+1):
        if i in d:
            result += str(d[i])
        else:
            result += "0"
    if len(result) != N:
        print("-1")
        return

    print(result)

if __name__ == "__main__":
    main()