#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[3];
  int c[9];
  map<int, int> q = {
      {1, 10},
      {2, 10},
      {3, 10},
  };
  bool j = true;
  for (int i = 0; i < m; i++) {
    int tc;
    int ts;
    cin >> ts >> tc;
    if ((q[ts - 1] == 10) || (q[ts - 1] == tc)) {
      q[ts - 1] = tc;
      c[i] = tc;
      s[i] = ts;
    } else {
      j = false;
    }
  }
  if (n > 1) {
    for (int i = 0; i < m; i++) {
      if ((s[i] == 1) && (c[i] == 0)) j = false;
    }
  }
  if (j == false) {
    cout << "-1" << endl;
    return 0;
  }
  int ans_a[3] = {1, 0, 0};
  int ans = 0;
  if (n == 1) ans_a[0] = 0;
  for (int i = 0; i < m; i++) {
    ans_a[s[i] - 1] = c[i];
  }
  if (n == 3) {
    ans = ans_a[0] * 100 + ans_a[1] * 10 + ans_a[2];
  } else if (n == 2) {
    ans = ans_a[0] * 10 + ans_a[1];
  } else if (n == 1) {
    ans = ans_a[0];
  }
  cout << ans << endl;
  return 0;
}
