# -*- coding: utf-8 -*-

def main():
    n, m = map(int, input().split())
    guess = [-1] * n
    ans = 0

    for i in range(m):
        s, c = map(int, input().split())
        if guess[s-1] == -1:
            guess[s-1] = c
        else:
            if guess[s-1] != c:
                return -1
    
    # 先頭に0がついている場合、ans = -1
    if guess[0] == 0:
        return -1
    elif guess[0] != -1:
        ans = guess[0]
    else:
        ans = 1

    for i in range(1, n):
        if guess[i] != -1:
            ans = ans * 10 + guess[i]
        else:
            ans = ans * 10

    return ans

if __name__ == "__main__":
    ans = main()
    print(ans)
