#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n, -1);
  bool dif = false;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (A[s] == -1 || A[s] == c)
      A[s] = c;
    else
      dif = true;
  }
  if (A[0] == 0 || dif) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); ++i) {
    if (A[i] != -1)
      cout << A[i];
    else
      cout << 0;
  }
  cout << endl;
  return 0;
}
