#include <bits/stdc++.h>
using namespace std;
bool check(int x, map<int, int> M) {
  string s = to_string(x);
  bool result = true;
  for (auto m : M) {
    cerr << s[m.first - 1] << " " << m.first << " " << m.second << endl;
    if (s[m.first - 1] - '0' != m.second) {
      result = false;
      break;
    }
  }
  return result;
}
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  bool chk = true;
  for (int i = 0; i < M; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    auto it = m.find(tmp1);
    if (it == m.end()) {
      m[tmp1] = tmp2;
    } else {
      if (m[tmp1] == tmp2) {
        continue;
      } else {
        chk = false;
        break;
      }
    }
  }
  if (N > 1 && m[1] == 0) {
    chk = false;
  }
  int i;
  bool digitchk;
  for (i = 0; i < 10000; i++) {
    digitchk = check(i, m);
    if (digitchk) {
      break;
    } else {
    }
  }
  if (chk) {
    cout << i << endl;
  } else {
    cout << -1 << endl;
  }
}
