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