#pragma region template

#include <bits/stdc++.h>

using namespace std;

// -type-
using str = string;
using ll = int64_t;
using pii = pair<int64_t, int64_t>;
using pis = pair<int64_t, str>;
using psi = pair<str, int64_t>;
using vi = vector<int64_t>;
using vvi = vector<vector<int64_t>>;
using vs = vector<str>;
using vpii = vector<pair<int64_t, int64_t>>;


//--const
constexpr ll MOD = 1000000007;

constexpr int INFI = int(0x3f000000);
constexpr ll INF = ll(0x3f0000003f000000);
constexpr double EPS = 1e-9;
constexpr int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
              dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// clang-format off
//--define
#define _overload3(_1, _2, _3, name, ...) name
#define   rep(...) _overload3(__VA_ARGS__,  _rep3,  _rep2,)(__VA_ARGS__)
#define  repc(...) _overload3(__VA_ARGS__, _repc3, _repc2,)(__VA_ARGS__)
#define  repr(...) _overload3(__VA_ARGS__, _repr3, _repr2,)(__VA_ARGS__)
#define repcr(...) _overload3(__VA_ARGS__,_repcr3,_repcr2,)(__VA_ARGS__)
#define _rep(i,k,n) for(int i=(k)   , i##_len=(n); i < i##_len; ++i)
#define   _rep2(i  ,n) _rep(i,0,n) 
#define   _rep3(i,k,n) _rep(i,k,n)
#define  _repc2(i  ,n) _rep(i,1,n+1)
#define  _repc3(i,k,n) _rep(i,k,n+1) 
#define _repr(i,k,n) for(int i=(n-1), i##_len=(k); i >=i##_len; --i)
#define  _repr2(i  ,n) _repr(i,0,n)
#define  _repr3(i,k,n) _repr(i,k,n) 
#define _repcr2(i  ,n) _repr(i,1,n+1)
#define _repcr3(i,k,n) _repr(i,k,n+1)
//rep-macro   normal, close, reverse, close+reverse

#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(...) debug_args(__LINE__, __VA_ARGS__)
#define pow2(n) (1LL<<(n))


//--functions
inline bool in(string s, string c) {return (s.find(c) != string::npos);}
inline bool in(string s,   char c) {return (s.find(c) != string::npos);}

template <class T> T udiv(T a, T b) {return (a + b - 1) / b;}
template <class T> T rdiv(T a, T b) {return (a + b / 2) / b;}

void print_args(ostream&) {}
template <class S, class... T>
void print_args(ostream& out,const S& a,const T&... args) {
    out << ' ' << a;
    print_args(out, args...);
}
template <class S, class... T>
void print(const S& a, const T&... args) {
    std::cout << a;
    print_args(std::cout, args...);
    std::cout << '\n';
}
template <class S, class... T>
void debug_args(const S& a, const T&... args) {
    std::cout << "(L:" << std::setw(3) << a << ")";
    print_args(std::cout, args...);
    std::cout << '\n';
}
// clang-format on

struct setup_main {
    setup_main() {
        std::cin.tie(0);
        std::ios::sync_with_stdio(0);
        std::cout << fixed << setprecision(15);
    }
} setup_main_;

ll ans(-1);
#pragma endregion
char itoc(int i) {
    return '0' + i;
}
int solve(long long N,
          long long M,
          std::vector<long long> s,
          std::vector<long long> c) {
    // array<int, 4> i = {0, 0, 0, 0};

    rep(k, 1000) {
        str ii = to_string(k);
        bool b = true;
        rep(j, M) {
            if (ii[s[j] - 1] != itoc(c[j])) b = false;
        }
        if (b and int(ii.size()) == N) return k;
    }
    return (-1);
    // }

    // if (N == 2) {
    //     for (i[1] = 1; i[1] < 10; i[1]++) {
    //         for (i[2] = 0; i[2] < 10; i[2]++) {
    //             ll ii = i[1] * 10 + i[2];
    //             rep(j, M) {
    //                 if (i[s[j]] != c[j]) ii = -1;
    //             }
    //             if (ii != -1) return ii;
    //         }
    //     }
    // }

    // if (N == 3) {
    //     for (i[1] = 1; i[1] < 10; i[1]++) {
    //         for (i[2] = 0; i[2] < 10; i[2]++) {
    //             for (i[3] = 0; i[3] < 10; i[3]++) {
    //                 ll ii = i[1] * 100 + i[2] * 10 + i[3];
    //                 rep(j, M) {
    //                     if (i[s[j]] != c[j]) ii = 0;
    //                 }
    //                 if (ii != 0) return ii;
    //             }
    //         }
    //     }
    // }
}
signed main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> s(M);
    std::vector<long long> c(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &s[i]);
        scanf("%lld", &c[i]);
    }
    print(solve(N, M, std::move(s), std::move(c)));

    return 0;
}


Measured memory_bytes: 256