#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#include <numeric>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

struct tmp{
    int s;
    int c;
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<tmp> a(m);
    for(int i=0; i<m; i++){
        cin >> a[i].s >> a[i].c;
    }

    sort(ALL(a), [](tmp aa, tmp bb){ return aa.s < bb.s; });
    if(a[0].s == 1 && a[0].c == 0){
        COUT("-1");
        return 0;
    }
    for(int i=1; i<m; i++){
        if(a[i-1].s == a[i].s && a[i-1].c != a[i].c){
            COUT("-1");
            return 0;
        }
    }

    int ans=0;
    for(int i=0; i<m; i++){
        if(i >= 1 && a[i].s == a[i-1].s) continue;
        int d = a[i].c;
        for(int j=0; j<n-a[i].s; j++){
            d *= 10;
        }
        // cout << a[i].c * pow(10, n-a[i].s) << endl; 
        ans += d;
    }

    COUT(ans);

    return 0;
}