#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(3, 0);
  vector<bool> flag(3, true);
  bool check = true;
  int k, c;
  for (int i = 0; i < (int)M; i++) {
    cin >> k >> c;
    if (flag[k - 1]) {
      flag[k - 1] = false;
      a[k - 1] = c;
    } else if (a[k - 1] == c) {
      continue;
    } else {
      check = false;
    }
  }
  if (check) {
    if (a[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 0; i < (int)N; i++) {
      cout << a[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
