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