#include <bits/stdc++.h>
#include <stdio.h>
#include <string>
#include <sstream>

using namespace std;

int main()
{
    int N;
    int M;
    cin >> N >> M;
    int S[M];
    int C[M];
    // vector<int> Ans(N);
    int Ans[N] = {};
    int Check[N] = {};
    for (int i = 0; i < M; i++) {
        cin >> S[i] >> C[i];
    }
    for (int i = 0; i < M; i++) {
        if(Check[S[i] - 1] == 0) {
            Ans[S[i] - 1] = C[i];
            Check[S[i] - 1] = 1;
        }else{
            cout << "-1" << endl;
            exit(0);
        }
    }
    if (Check[0] == 0){
        cout << "-1" << endl;
        exit(0);
    }

    string Answer_str;
    for (int j = 0; j < N; j++) {
        Answer_str += to_string(Ans[j]);
    }
    int Answer = atoi(Answer_str.c_str());
    cout << Answer << endl;
}
