#include <bits/stdc++.h>
using namespace std;
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.at(i) >> c.at(i);
  }
  vector<int> t(m);
  for (int i = 0; i < n; i++) t[i] = -1;
  for (int j = 0; j < m; j++) {
    if (t[s[j] - 1] == -1)
      t[s[j] - 1] = c[j];
    else if (t[s[j] - 1] != c[j]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1)
    t[0] = max(t[0], 0);
  else if (t[0] > 0)
    t[0] = max(t[0], 1);
  else
    cout << -1 << endl;
  return 0;
  for (int i = 1; i < n; i++) {
    if (t[i] == -1) t[i] = 0;
  }
  int ans = 0;
  int v;
  for (int i = 0; i < n; i++) {
    v = (int)pow(10, n - i - 1);
    ans += t[i] * v;
  }
  cout << ans << endl;
  return 0;
}
