#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    sc[i] = make_pair(s - 1, c);
  }
  sort(sc.begin(), sc.end());
  vector<int> memo(n, 0);
  int last_s = -1;
  int last_c = -1;
  for (int i = 0; i < m; i++) {
    if (0 == sc[i].first & 0 == sc[i].second & 1 != n) {
      cout << -1;
      return 0;
    }
    if (sc[i].first == last_s) {
      if (sc[i].second != last_c) {
        cout << -1;
        return 0;
      }
    }
    last_s = sc[i].first;
    last_c = sc[i].second;
  }
  for (int i = 0; i < m; i++) {
    memo[sc[i].first] = sc[i].second;
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    int d;
    if (i == 0) {
      if (0 == memo[i]) {
        d = 1;
      } else {
        d = memo[i];
      }
    } else {
      d = memo[i];
    }
    ret += d * pow(10, n - i - 1);
  }
  cout << ret << endl;
  return 0;
}
