#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s, c, sum = 0, cnt;
  bool f = true;
  cin >> n >> m;
  vector<pair<bool, int>> v(n + 1);
  for (int i = 0; i < n; i++) v.at(i).second = 0;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (n != 1 && s == 1 && c == 0) {
      f = false;
    }
    if (v.at(s).first == false) {
      v.at(s).first = true;
      v.at(s).second = c;
    } else {
      if (v.at(s).second != c) {
        f = false;
      }
    }
  }
  if (f == false) {
    cout << -1 << endl;
    return 0;
  }
  cnt = n - 1;
  for (int i = 1; i < n + 1; i++) {
    sum += v.at(i).second * pow(10, cnt);
    cnt--;
  }
  cout << sum << endl;
  return 0;
}
