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