#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    int n, m;
    cin >> n >> m;
    vector<int>s(m);
    vector<int>c(m);
    vector<int>cnt(3),cnt2(3);
    rep(i, 3)cnt[i] = -101,cnt2[i] = 0;
    int ans = 0;
    
    rep(i, m) {
        cin >> s[i] >> c[i];
        if (n == 1) {
            if (s[i] > 1) {
                cout << -1 << endl;
                return 0;
            }
            else {
                if (cnt[0] !=  c[i] && cnt2[0] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[0] == 0) {
                    ans += c[i];
                }
                cnt2[0]++;
                cnt[0] = c[i];
            }
        }
        else if (n == 2) {
            if (s[i] > 2) {
                cout << -1 << endl;
                return 0;
            }
            else {
                if (s[i] == 2) {
                    if (cnt[1] != c[i] && cnt2[1] != 0) {
                        cout << -1 << endl;
                        return 0;
                    }
                    if (cnt2[1] == 0) {
                        ans += c[i];
                    }
                    cnt2[1]++;
                    cnt[1] = c[i];
                }
                else if (s[i] == 1) {
                    if (cnt[0] != c[i] && cnt2[0] != 0) {
                        cout << -1 << endl;
                        return 0;
                    }
                    if (c[i] == 0) {
                        cout << -1 << endl;
                        return 0;
                    }
                    if (cnt2[0] == 0) {
                        ans += c[i] * 10;
                    }
                    cnt2[0]++;
                    cnt[0] = c[i];
                }
            }
        }
        else {
            if (s[i] == 3) {
                if (cnt[2] != c[i] && cnt2[2] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[2] == 0) {
                    ans += c[i];
                }
                cnt2[2]++;
                cnt[2] = c[i];
            }
            if (s[i] == 2) {
                if (cnt[1] != c[i] && cnt2[1] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[1] == 0) {
                    ans += c[i] * 10;
                }
                cnt2[1]++;
                cnt[1] = c[i];
            }
            else if (s[i] == 1) {
                if (cnt[0] != c[i] && cnt2[0] != 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (c[i] == 0) {
                    cout << -1 << endl;
                    return 0;
                }
                if (cnt2[0] == 0) {
                    ans += c[i] * 100;
                }
                cnt2[0]++;
                cnt[0] = c[i];
            }
        }
        
    }
    if (n == 2 && cnt2[0] == 0)ans = ans + 10;
    if (n == 3 && cnt2[0] == 0)ans = ans + 100;
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

bool intCheck(int i, int N, int M, vector<int> S, vector<int> C) {
    string sx = to_string(i);
    if (sx.size() != N) return false;
    for (int j = 0; j < M; j++) {
        if (sx.at(S.at(j)) != (char)C.at(j) + '0') return false;
    }
    return true;
}

int main() {
    int N, M; cin >> N >> M;
    vector<int> s(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> s.at(i) >> c.at(i);
        s.at(i)--;
    }

    bool ans = true;
    int minv = 1e5, nf = -1;
    for (int i = 0; i < 1000; i++) {
        if (intCheck(i, N, M, s, c)) {
            cout << i << endl;
            return 0;
        }
    }
    cout << nf << endl;
}