#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N, M;
    int flag = 1;
    string ans = "";
    map<int, string> m;
    m[1] = "a";
    m[2] = "a";
    m[3] = "a";
    cin >> N >> M;
    rep(i,M){
        int s;cin >> s;
        string c;cin >> c;
        if(m[s] == "a") m[s] = c;
        else{
            if(m[s] != c) flag = 0;
        }
    }
    if(N == 1){
        if(m[2] != "a" or m[3] != "a") flag = 0;
    }
    if(N == 2){
        if(m[3] != "a") flag = 0;
    }
    if(flag && m[1] != "0"){
        rep(i,N){
            if(i == 0 && m[i+1] == "a") cout << "1";
            else{
                if(m[i+1] == "a") cout << "0";
                else cout << m[i+1];
            }
        }
        cout << endl;
    }
    else cout << -1 << endl;
}
