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