#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int N = 1;
  for (int i = 0; i < (int)(n - 1); i++) N *= 10;
  int d[5];
  d[0] = 1;
  for (int i = 0; i < (int)(4); i++) d[i + 1] = d[i] * 10;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s[i] >> c[i];
  for (int i = (int)(N); i <= (int)(N * 10 - 1); i++) {
    bool ng = false;
    for (int j = 0; j < (int)(m); j++) {
      if ((i / d[n - s[j]]) % 10 != c[j]) {
        ng = true;
        break;
      }
    }
    if (!ng) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
