#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++)

template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}


Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

void y() {
    cout << "Yes" << endl;
    exit(0);
}

void n() {
    cout << "No" << endl;
    exit(0);
}

void Y() {
    cout << "YES" << endl;
    exit(0);
}

void N() {
    cout << "NO" << endl;
    exit(0);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}

/*   kokomade  */

int cnt = 0;
bool is_prime[ 50000 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
vector< int64_t > divisor(int64_t n) {
    vector< int64_t > ret;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}


void euclid(Int N, Int a, Int b)
{
    for (Int d = a+b; d <= N; d += b) {
        //cout << b << ", " << d << endl;
        euclid(N, b, d);
    }
}

Int fact_mod(Int n, Int mod) {
    Int f = 1; repq(i,2,n) f = f * (i % MOD) % MOD;
    return f;
}

// 繰り返し二乗法 (modの世界での累乗)
Int mod_pow(Int x, Int n, Int mod) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

// 組み合わせ nCr を求める
Int combination_mod(Int n, Int r, Int mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    Int a = 1;
    rep(i, 0, r) a = a * ((n-i) % mod) % mod;
    Int b = mod_pow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}
int main() {
    //COMinit();
    IOS;
    prec;
    Int a,b,n,k,x,m,y=0,ans=0;
    string str,t,u;
    cin>>n>>m;
    if(m==0){
        if (n==1)cout<<0;
        if (n==2)cout<<10;
        if (n==3)cout<<100;
        cout<<endl;
        return 0;
    }
    //if(m>n){
    //    cout<<-1<<endl;
    //    return 0;
    //}
    vector<int>s(m),c(m);
    for (int i = 0; i < m; ++i) {
        cin>>s[i]>>c[i];
    }
    vector<int>n1,n2,n3;
    for (int j = 0; j < m; ++j) {
        if(s[j]==1){
            n1.push_back(c[j]);
        }
        if(s[j]==2){
            n2.push_back(c[j]);
        }
        if(s[j]==3){
            n3.push_back(c[j]);
        }
    }
    int nn1=n1.size();
    int nn2=n2.size();
    int nn3=n3.size();

    ssort(n1);eerase(n1);
    ssort(n2);eerase(n2);
    ssort(n3);eerase(n3);
    vector<int>anz;
    if (n==1){
        if(n1.size()==0)anz.push_back(0);
        else{
            if(n1.size()!=1)cout<<-1;
            else{
                anz.push_back(n1[0]);
            }
        }
        cout<<endl;
    }
    if(n==2){
        if(n1.size()==0)anz.push_back(1);
        else{
            if(n1.size()!=1){
                cout<<-1<<endl;
                return 0;
            }
            else{
                if(n1[0]==0){
                    cout<<-1<<endl;
                    return 0;
                }
                anz.push_back(n1[0]);
            }
        }
        if(n2.size()==0)anz.push_back(0);
        else{
            if(n2.size()!=1){
                cout<<-1<<endl;
                return 0;
            }
            else{
                anz.push_back(n2[0]);
            }
        }
    }
    if(n==3){
        if(n1.size()==0)anz.push_back(1);
        else{
            if(n1.size()!=1){
                cout<<-1<<endl;
                return 0;
            }
            else{
                if(n1[0]==0){
                    cout<<-1<<endl;
                    return 0;
                }
                anz.push_back(n1[0]);
            }
        }
        if(n2.size()==0)anz.push_back(0);
        else{
            if(n2.size()!=1){
                cout<<-1<<endl;
                return 0;
            }
            else{
                anz.push_back(n2[0]);
            }
        }
        if(n3.size()==0)anz.push_back(0);
        else{
            if(n3.size()!=1){
                cout<<-1<<endl;
                return 0;
            }
            else{
                anz.push_back(n3[0]);
            }
        }
    }
    for (int l = 0; l <anz.size(); ++l) {
        cout<<anz[l];
    }




    cout<<endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 256