#include <bits/stdc++.h>
using namespace std;
inline void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
inline void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
inline void Yay(bool b) { cout << (b ? "Yay!" : ":(") << endl; }
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(15);
  int N, M;
  cin >> N >> M;
  int N_ = 1;
  for (int i = 0, i_max = (N - 1); i < i_max; ++i) N_ *= 10;
  vector<pair<int, int> > v(M);
  for (int i = 0, i_max = (M); i < i_max; ++i) {
    cin >> v[i].first >> v[i].second;
    v[i].first = N - v[i].first;
  }
  for (int x = 0, x_max = (1000); x < x_max; ++x) {
    if (x == 0) {
      bool sat = true;
      for (int i = 0, i_max = (M); i < i_max; ++i) {
        if (N != 1 || v[i].second != 0) sat = false;
      }
      if (sat) {
        cout << x << endl;
        return 0;
      }
    }
    if (x < N_ || x >= 10 * N_) continue;
    bool sat = true;
    for (int i = 0, i_max = (M); i < i_max; ++i) {
      int s_ = 1;
      for (int j = 0, j_max = (v[i].first); j < j_max; ++j) s_ *= 10;
      if ((x / s_) % 10 != v[i].second) sat = false;
    }
    if (sat) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
