#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;

    int A[N];
    int ans;

    for (int i = 0; i < N; i++){
        A[i] = 0;
    }

    for (int i = 0; i < M; i++){
        int s, c;
        cin >> s >> c;
        if (A[s-1] == 0){
            A[s-1] = c;
        }
        else if (A[s-1] == c){
            A[s-1] = c;
        }
        else {
            ans = -1;
        }
    }

    else if (N == 3 && A[0] != 0){
        ans = A[0] * 100 + A[1] * 10 + A[2];
    }
    else if (N == 2 && A[0] != 0){
        ans = A[0] * 10 + A[1];
    }
    else if (N == 1){
        ans = A[0];
    }
    else {
        ans = -1;
    }

    cout << ans << endl;
}
