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