#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  bool f = true;
  cin >> N >> M;
  vector<int> s(M), c(M), ans(N);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s.at(i) >> c.at(i);
    ans.at(s.at(i) - 1) = c.at(i);
  }
  for (int i = 0; i < (int)(M); i++) {
    for (int j = 0; j < (int)(M); j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        f = false;
        break;
      } else if (N != 1 && ans.at(0) == 0) {
        f = false;
        break;
      }
    }
    if (f == false) {
      break;
    }
  }
  if (f) {
    for (int i = 0; i < (int)(N); i++) {
      cout << ans.at(i);
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
}
