#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
vector<ii> a;
int n ,m;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    for(int i = 0 ; i < m ; ++i){
        int u , v;cin >> u >> v;
        a.pb(mp(u,v));
    }
    for(int i = 0 ; i <= 999 ; ++i){
        int lg = log10(i) + 1;
        if(lg != n)continue;
        string s = to_string(i);
        bool ok = 1;
        for(auto c : a){
            if(s[c.first - 1] != '0' + c.second)ok = 0;
        }
        if(ok == 0)continue;
        return cout << i , 0;
    }
    cout << -1;
}
