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