#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  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) {
      ans[s] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (ans[i] == 0) {
        cout << -1 << endl;
        return 0;
      } else {
        cout << max(ans[i], 1);
      }
      continue;
    }
    cout << max(ans[i], 0);
  }
  cout << endl;
  return 0;
}
