#include<iostream>
#include<math.h>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N, M;
    cin >> N >> M;
    int s, c, tmp[N] = {}, ans = 0;
    Fp(i, 0, M){
        cin >> s >> c;
        if(tmp[s - 1] == 0 || tmp[s - 1] == c){
            if(s == 1 && c == 0){
                cout << -1 << endl;
                return 0;
            }else tmp[s - 1] = c;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    Fp(i, 0, N) ans += tmp[i] * pow(10, N - i - 1);
    if((ans - pow(10, N - 1)) < 0) ans += pow(10, N - 1);
    cout << ans << endl;
}
