#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec(m);
  vector<int> ans(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    cin >> vec[i].first >> vec[i].second;
  }
  for (int i = 0; i < (int)(m); i++) {
    int k = vec[i].first - 1;
    int num = vec[i].second;
    if (k == 0 && num == 0) {
      cout << -1 << endl;
      ;
      return 0;
    }
    if (ans[k] == -1 || ans[k] == num) {
      ans[k] = num;
    } else {
      cout << "-1" << endl;
      ;
      return 0;
    }
  }
  if (ans[0] == -1) {
    ans[0] = 1;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (ans[i] == -1) {
      cout << 0;
    } else {
      cout << ans[i];
    }
  }
  cout << endl;
  return 0;
}
