#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m, i, p, d;
  cin >> n >> m;
  if (n >= m) {
    long long int A[n];
    for (i = 0; i < n; i++) A[i] = -1;
    for (i = 0; i < n; i++) {
      cin >> p >> d;
      if (A[p - 1] == -1 || A[p - 1] == d)
        A[p - 1] = d;
      else {
        cout << "-1\n";
        return;
      }
    }
    if (n > 1 && A[0] == 0)
      cout << "-1\n";
    else {
      if (A[0] == -1) A[0] = 1;
      for (i = 1; i < n; i++) {
        if (A[i] == -1) A[i] = 0;
      }
      for (i = 0; i < n; i++) cout << A[i];
      cout << "\n";
    }
  } else
    cout << "-1\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
