#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (v[a - 1] != -1 && v[a - 1] != b) {
      cout << "-1" << endl;
      return 0;
    }
    v[a - 1] = b;
  }
  if (n == 1) {
    cout << (v[0] == -1 ? 0 : v[0]) << endl;
    return 0;
  }
  if (v[0] == -1 || v[0] == 0) {
    v[0] = 1;
  }
  for (int i = 0; i < n; ++i) {
    cout << (v[i] == -1 ? 0 : v[i]);
  }
  cout << endl;
}
