#include <bits/stdc++.h>
const int INF = (int)1e9 + 10;
const long long MOD = (long long)1e9 + 7;
const long long LINF = (long long)4e18 + 20;
const long double PI = acos(-1.0);
const double EPS = 1e-9;
using namespace ::std;
int keta(int n) {
  int ans = 0;
  if (n == 0) {
    return 1;
  }
  while (n) {
    n /= 10;
    ++ans;
  }
  return ans;
}
void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  for (int i = 0; i < M; ++i) {
    cin >> S[i] >> C[i];
  }
  for (int i = 0; i < 1000; ++i) {
    int ter = i;
    bool flag = true;
    int res;
    for (int j = 0; j < M && flag; ++j) {
      switch (S[j]) {
        case 1:
          res = ter / 100;
          if (res != C[j]) {
            flag = false;
          }
          break;
        case 2:
          res = (ter / 10) % 10;
          if (res != C[j]) {
            flag = false;
          }
          break;
        case 3:
          res = ter % 10;
          if (res != C[j]) {
            flag = false;
          }
      }
    }
    if (flag) {
      if (keta(i) == N) {
        cout << i << endl;
        return;
      }
    }
  }
  cout << -1 << endl;
}
signed main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed;
  cout << setprecision(16);
  solve();
}
