#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> c(n, -1);
  int x, v, j = 0;
  for (int i = 0; i < m; i++) {
    cin >> x >> v;
    if (c.at(x - 1) != -1) {
      if (c.at(x - 1) != v) {
        j = 1;
      }
    } else
      c.at(x - 1) = v;
  }
  if (c.at(0) == 0) j = 1;
  for (int i = 0; i < 3; i++) {
    if (c.at(i) == -1) {
      if (i == 0)
        c.at(i) = 1;
      else
        c.at(i) = 0;
    }
  }
  int ans = c.at(0) * 100 + c.at(1) * 10 + c.at(2);
  if (j == 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
