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