#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    SC = sorted(zip(s, c))

    ans = [-1]*N
    for s, c in SC:
        if s > N:
            print(-1)
            return
        if ans[s-1] == -1:
            ans[s-1] = c
        else:
            if ans[s-1] != c:
                print(-1)
                return

    if ans[0] == -1:
        ans[0] = "1"
    else:
        ans[0] = str(ans[0])
    for i in range(1, N):
        if ans[i] == -1:
            ans[i] = "0"
        else:
            ans[i] = str(ans[i])
    ans = "".join(ans)
    if ans == "000":
        print(-1)
    else:
        print("".join(ans))
    return


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()
