#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    vector<bool> b(n);
    bool t = true;
    REP(i, m) {
        int s, c; cin >> s >> c;
        s--;
        if (n != 1 && s == 0 && c == 0) t = false;
        if (b[s] && a[s] != c) t = false;
        a[s] = c; b[s] = true;
    }
    if (t) {
        if (a[0] == 0) s[0] = 1;
        for (auto v : a) cout << v;
    }
    else cout << -1;
    cout << endl;
}