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