#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  int si, ci;
  vector<int> v(3, -1);
  bool no = false;
  for (int i = 0; i < m; i++) {
    cin >> si >> ci;
    if (v[3 - si] == -1) {
      v[3 - si] = ci;
    } else {
      if (v[3 - si] != ci) {
        no = true;
      }
    }
  }
  bool is0 = true;
  int ans = 0;
  for (int i = n - 1; i > -1; i--) {
    if (v[i] == -1 and is0 == true) {
      ans += pow(10, i);
      is0 = false;
    } else if (v[i] == -1) {
      ans += 0;
    } else {
      ans += pow(10, i) * v[i];
    }
    if (ans > 0) {
      is0 = false;
    }
  }
  if (no or pow(10, n - 1) > ans) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
}
