def resolve():
    n, m = map(int, input().split())
    arr = [None, None, None]
    for i in range(m):
        s, c = map(int, input().split())
        j = s - 1
        if arr[j] is None or arr[j] == c:
            arr[j] = c
        else:
            return print(-1)

    if arr[0] == 0:
        return print(-1)

    arr = [0 if e is None else e for e in arr]

    print(str(arr[0])+str(arr[1])+str(arr[2]))


if __name__ == '__main__':
    resolve()
