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

int main() {
    int n, m;
    cin >> n >> m;
    int S[m] = {};
    int C[m] = {};
    for(int i = 1; i < m+1; i++){
        cin >> S[i] >> C[i];
    }
    int A[n] = {};

    for(int i = 1; i < m+1; i++){
        for(int j = 1; j < i; j++){
            if(S[i] == S[j] && C[i] != C[j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(int i = 1; i < n+1; i++){
        for(int j = 1; j < m+1; j++){
            if(i == S[j]){
                A[i] = C[j];
            }
        }
    }



    int count = 0;
    if(n == 1){
        count = A[1];
        if(0 <= count && count < 10){
            cout << count << endl;
            return 0;
        }
    }else if (n == 2){
        count = 10 * A[1] + A[2];
        if(10 <= count && count < 100){
            cout << count << endl;
            return 0;
        }
    }else{
        count = 100 * A[1] + 10 * A[2] + A[3];
        if(100 <= count && count < 1000){
            cout << count << endl;
            return 0;
        }
    }
    
    cout << -1 << endl;
    return 0;
    
}
