#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    int value = i;
    int OK = 1;
    for (int j = 1; j <= N; j++) {
      int jth_num = value % 10;
      value /= 10;
      for (int k = 0; k < (int)(M); k++) {
        if (s.at(k) == N - j + 1) {
          int c_ = c.at(k);
          if (c_ != jth_num) {
            OK = 0;
            break;
          }
        }
      }
    }
    if (OK) {
      cout << i << endl;
      exit(0);
    }
  }
  cout << -1 << endl;
}
