#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);
  for (int i = 0; i < m; i++) {
    if (0 == sc[i].first & 0 == sc[i].second & 1 != n) {
      cout << -1;
      return 0;
    }
    if (0 != memo[sc[i].first] & sc[i].second != memo[sc[i].first]) {
      cout << -1;
      return 0;
    }
    memo[sc[i].first] = sc[i].second;
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    ret += memo[i] * pow(10, n - i - 1);
  }
  cout << ret << endl;
  return 0;
}
