#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define sc second
#define ve vector
#define tos to_string
#define len length
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// abs 絶対値, rtsq ルート, pow(a, n) aのn乗

int main() {
  int N, M;
  ci(N, M);
  ve<int> s(M), c(M);
  rep(i, M){
    ci(s.at(i), c.at(i));
  }
  rep(i, 1000){
    int A = 0;
    rep(j, M){
      if(tos(i).len == 1){
        if(s.at(j) == 3 && i % 10 == c.at(j)){
          A++;
        }
      }
      if(tos(i).len == 2){
        if(s.at(j) == 3 && i % 10 == c.at(j)){
          A++;
        }
        else if(s.at(j) == 2 && (i % 100) / 10 == c.at(j)){
          A++;
        }
      }
      if(tos(i).len == 3){
        if(s.at(j) == 3 && i % 10 == c.at(j)){
          A++;
        }
        else if(s.at(j) == 2 && (i % 100) / 10 == c.at(j)){
          A++;
        }
        else if(s.at(j) == 1 && i / 100 == c.at(j)){
          A++;
        }
      }
    }
    if(A == M && tos(i).len() == N){
      co(i);
      return 0;
    }
  }
  co(-1);
}