#include <bits/stdc++.h>
using namespace std;
int N_MAX = 5;
int main() {
  int n, m, t, cc, i, res = 0;
  int c[N_MAX];
  cin >> n >> m;
  fill(c, c + n, -1);
  for (i = 0; i < m; i++) {
    cin >> t >> cc;
    if (c[t - 1] == -1 || c[t - 1] == cc) {
      c[t - 1] = cc;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (c[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (c[0] == -1)
    res = 1;
  else
    res = c[0];
  for (i = 1; i < n; i++) {
    res *= 10;
    if (c[i] != -1) res += c[i];
  }
  cout << res << endl;
  return 0;
}
