#include <bits/stdc++.h>
using namespace std;
int N, M;
int s[3];
int main() {
  cin >> N >> M;
  for (long long i = 0; i < (long long)(M); i++) {
    s[i] = 10;
  }
  for (long long i = 0; i < (long long)(M); i++) {
    int at, in;
    cin >> at >> in;
    if (N < at) {
      cout << -1 << endl;
      return 0;
    }
    if (s[at - 1] != 10 && s[at - 1] != in) {
      cout << -1 << endl;
      return 0;
    }
    s[at - 1] = in;
  }
  for (long long i = 0; i < (long long)(N); i++) {
    if (s[i] == 10) {
      s[i] = 0;
    }
  }
  if (N == 1) {
    cout << s[0] << endl;
  } else if (N == 2) {
    if (s[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << 10 * s[0] + s[1] << endl;
  } else {
    if (s[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << 100 * s[0] + 10 * s[1] + s[2] << endl;
  }
  return 0;
}
