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

    if arr[0] == '0' and n >= 2:
        return print(-1)

    if arr[0] is None and n == 1:
        return print(-1)

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

    print(''.join(arr))


if __name__ == '__main__':
    resolve()