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