#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,M;cin >> N >> M;
    vector<int> s(M);
    vector<int> c(M);
    rep(i,M)cin >> s[i] >> c[i];

    bool ok = false;
    int ans = 0;

    if(M != 0){
        if(N == 1){
            int a = c[0];
            rep(i,M){
                if(c[i] != a)ok = true;
            }
            ans = a;
        }
        else if(N == 2){
            bool c1 = false;
            bool c2 = false;
            int n1 = -1;
            int n2 = -1;

            rep(i,M){
                int ts = s[i];
                int tc = c[i];
                if(ts == 1){
                    if(!c1){
                        n1 = tc;
                        c1 = true;
                        if(n1 == 0)ok = true;
                    }
                    else{
                        if(n1 != tc)ok = true;
                    }
                }
                if(ts == 2){
                    if(!c2){
                        n2 = tc;
                        c2 = true;
                    }
                    else{
                        if(n2 != tc)ok = true;
                    }
                }
                if(n1 == -1)n1 = 1;
                if(n2 == -1)n2 = 0;
                ans = n1*10 + n2;
            }
        }
        else{
            bool c1 = false;
            bool c2 = false;
            bool c3 = false;
            int n1 = -1;
            int n2 = -1;
            int n3 = -1;

            rep(i,M){
                int ts = s[i];
                int tc = c[i];
                if(ts == 1){
                    if(!c1){
                        n1 = tc;
                        c1 = true;
                        if(n1 == 0)ok = true;
                    }
                    else{
                        if(n1 != tc)ok = true;
                    }
                }
                if(ts == 2){
                    if(!c2){
                        n2 = tc;
                        c2 = true;
                    }
                    else{
                        if(n2 != tc)ok = true;
                    }
                }
                if(ts == 3){
                    if(!c3){
                        n3 = tc;
                        c3 = true;
                    }
                    else{
                        if(n3 != tc)ok = true;
                    }
                }
                if(n1 == -1)n1 = 1;
                if(n2 == -1)n2 = 0;
                if(n3 == -1)n3 = 0;
                ans = n1*100 + n2*10 + n3;            
            }
        }
    }
    else{
        if(N == 3)ans = 100;
        if(N == 2)ans = 10;
        if(N == 1)ans = 0;
    }

    if(ok)cout << "-1" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 256