#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int main(void) {
  int N;
  int M;
  cin >> N >> M;
  int s, c;
  int a[3] = {-1, -1, -1};
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (a[s - 1] == -1) {
      a[s - 1] = c;
    } else if (a[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  int temp = 0;
  if (a[3 - N] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 2; i >= 3 - N; i--) {
    if (a[i] == -1) {
      a[i] = 0;
    }
    temp += a[i] * pow(10, 2 - i);
  }
  cout << temp << endl;
}
