#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using P = pair<long long, long long>;
signed main() {
  long long N, M;
  cin >> N >> M;
  long long first, last;
  if (N == 0) {
    first = 0;
    last = 9;
  } else if (N == 1) {
    first = 10;
    last = 99;
  } else {
    first = 100;
    last = 999;
  }
  P input[M];
  for (long long i = 0; i < (M); ++i) {
    cin >> input[i].first >> input[i].second;
  }
  for (long long i = first; i <= last; i++) {
    bool flag = false;
    string S = to_string(i);
    for (long long j = 0; j < (M); ++j) {
      if (S[input[j].first - 1] == '0' + input[j].second)
        ;
      else {
        flag = true;
        break;
      }
    }
    if (flag)
      ;
    else {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
