#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != -1 && ans[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c;
  }
  if (ans[0] == 0 && n > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << (ans[i] != -1 ? ans[i] : (i == 0 ? 1 : 0));
  }
  cout << endl;
  return 0;
}
