# -*- coding: utf-8 -*-
n, m = map(int,input().split())
if n == 1:
    ans = -1
    if m == 0:
        print(0)
        exit()
    for _ in range(m):
        s, c = map(int,input().split())
        if ans == -1 or ans == c:
            ans = c
    print(ans)
else:
    ans = [-1 for _ in range(n)]
    for _ in range(m):
        s, c = map(int,input().split())
        if s == 1 and c == 0:
            print(-1)
            exit()
        if ans[s - 1] == -1 or ans[s - 1] == c:
            ans[s - 1] = c
        else:
            print(-1)
            exit()
    flag = True
    for i in range(n):
        if ans[i] == -1:
            ans[i] = 0
        if ans[i] >= 1:
            flag = False
        if ans[i] == 0 and flag:
            ans[i] = 1
    for i in range(n):
        ans[i] = str(ans[i])
    print(''.join(ans))
