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