#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, num = 0;
  cin >> n >> m;
  vector<int> s(n), c(n), ans(n);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (ans[s[i] - 1] == 0 || ans[s[i] - 1] == c[i]) {
      ans[s[i] - 1] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    num += ans[i] * pow(10, (n - 1) - i);
  }
  cout << num << endl;
  return 0;
}
