#include <bits/stdc++.h>
using namespace std;
void YN(bool flg) {
  if (flg)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void Yn(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void yn(bool flg) {
  if (flg)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  int mx = 1;
  for (int i = 0; i < (int)(n); i++) {
    mx *= 10;
  }
  bool out = false;
  vector<int> check(3, -1);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (check[s] != -1 && check[s] != c) out = true;
    check[s] = c;
    if (n >= 2 && check[0] == 0) out = true;
  }
  if (out) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 114514;
  for (int i = 0; i < (int)(mx); i++) {
    string t = to_string(i);
    bool ok = true;
    for (int j = 0; j < (int)(3); j++) {
      if (check[j] == -1) continue;
      if (j >= n) continue;
      if (t[j] != check[j] + '0') ok = false;
    }
    if (ok) ans = min(ans, i);
  }
  cout << (ans == 114514 ? -1 : ans) << endl;
  return 0;
}
