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