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