#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  int st = 1;
  for (int i = 0; i < (n - 1); ++i) st *= 10;
  auto bit_num = [](int n, int bit) {
    int dig = 1;
    for (int i = 0; i < (bit - 1); ++i) dig *= 10;
    return (n % (dig * 10)) / dig;
  };
  for (int i = st; i < st * 10; i++) {
    bool end = false;
    for (int j = 0; j < (m); ++j) {
      if (bit_num(i, n - s[j] + 1) != c[j]) end = true;
      ;
    }
    if (end) continue;
    cout << i << endl;
    return 0;
  }
  cout << -1 << endl;
}
