#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[10], C[10];
int p10[5];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  p10[0] = 1;
  p10[1] = 10;
  p10[2] = 100;
  p10[3] = 1000;
  p10[4] = 10000;
  cin >> N >> M;
  for (i = 0; i < (M); i++) {
    cin >> S[i] >> C[i];
    S[i] = N - S[i];
  }
  for (i = p10[N - 1]; i < p10[N]; i++) {
    int ng = 0;
    for (j = 0; j < (M); j++)
      if (i / p10[S[j]] % 10 != C[j]) ng++;
    if (ng == 0) return (void)printf("%d\n", i);
  }
  cout << -1 << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
