#include <bits/stdc++.h>
int get_scale(int power) {
  int scale;
  int i;
  scale = 1;
  i = 0;
  while (i < power) {
    scale *= 10;
    ++i;
  }
  return (scale);
}
bool is_feasible(int n, int m, int *s, int *c, int num) {
  int i;
  i = 0;
  while (i < m) {
    if ((num / get_scale(n - s[i])) % 10 != c[i]) return (false);
    ++i;
  }
  return (true);
}
int main() {
  using namespace std;
  int n;
  int m;
  int s[5];
  int c[5];
  int i;
  bool found;
  int upper;
  cin >> n >> m;
  i = 0;
  while (i < m) {
    cin >> s[i] >> c[i];
    ++i;
  }
  i = get_scale(n - 1);
  found = false;
  upper = get_scale(n);
  while (i < upper) {
    if (is_feasible(n, m, s, c, i)) {
      found = true;
      cout << i << endl;
      break;
    }
    ++i;
  }
  if (!found) cout << -1 << endl;
  return (0);
}
