#!/usr/bin/env python3
import sys


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    restriction = [-1 for i in range(N)]
    for i in range(M):
        rC = s[i]-1
        rV = c[i]
        if restriction[rC] != -1 and restriction[rC] != rV:
            print("-1")
            return
        else:
            restriction[rC] = rV
    number = ""
    for i in range(N):
        if i == 0 and restriction[i] == 0:
            print("-1")
            return
        if restriction[i] != -1:
            number+=str(restriction[i])
        else:
            number+="1" if i == 0 else "0"
    print(number)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()
