#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int ANS[3];
  vector<int> s;
  vector<int> c;
  for (int i = 0; i < 3; i++) ANS[i] = -1;
  cin >> N >> M;
  int i, j, k;
  for (i = 0; i < M; i++) {
    int temp_s, temp_c;
    cin >> temp_s >> temp_c;
    s.push_back(temp_s);
    c.push_back(temp_c);
  }
  for (i = 0; i < M; i++) {
    for (j = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (i = 0; i < M; i++) {
    ANS[s.at(i) - 1] = c.at(i);
  }
  if (ANS[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (ANS[0] == -1) ANS[0] = 1;
  if (ANS[1] == -1) ANS[1] = 0;
  if (ANS[2] == -1) ANS[2] = 0;
  for (i = 0; i < N; i++) {
    cout << ANS[i];
  }
  cout << endl;
  return 0;
}
