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