#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    result = [0] * N

    for m in range(M):
        s, c = map(int, input().split())
        if s == 1 and c == 0:
            print(-1)
            exit(0)

        if result[s - 1] == c:
            continue
        elif result[s - 1] != 0:
            print(-1)
            exit(0)
        else:
            result[s - 1] = c

    if result[0] == 0:
        result[0] = 1
    result = int(''.join([str(r) for r in result]))

    if len(list(str(result))) == N:
        print(result)
    else:
        print(-1)


if __name__ == "__main__":
    main()
