#include <bits/stdc++.h>
const char sp = ' ';
using namespace std;
int main(void) {
  int N, M, di[4], s, c;
  cin >> N >> M;
  for (int i = 0, i_len = (4); i < i_len; ++i) di[i] = 10;
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    cin >> s >> c;
    if (di[s] != 10 && di[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    if (s > N) {
      cout << -1 << endl;
      return 0;
    }
    di[s] = c;
  }
  if (di[1] == 0) {
    if (N == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1, i_len = (N); i <= i_len; ++i) {
    if (di[i] == 10) {
      if (i == 1)
        di[i] = 1;
      else
        di[i] = 0;
    }
  }
  int count = 0;
  for (int i = 1, i_len = (3); i <= i_len; ++i) {
    N--;
    count += di[i] * pow(10, N);
    if (N == 0) break;
  }
  cout << count << endl;
  return 0;
}
