#include <bits/stdc++.h>
using namespace std;
int N, M;
int s[5], c[5];
int Ans[3] = {-1, -1, -1};
int Ansnum = 0;
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (Ans[s[i] - 1] == -1 or Ans[s[i] - 1] == c[i]) {
      Ans[s[i] - 1] = c[i];
    } else {
      Ansnum = -1;
      break;
    }
  }
  if (Ans[0] == 0) {
    Ansnum = -1;
  }
  if (Ansnum == 0) {
    if (Ans[0] == -1) Ans[0] = 1;
    for (int i = 1; i < N; i++) {
      if (Ans[i] == -1) Ans[i] = 0;
    }
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        Ans[i] = Ans[i] * 10;
      }
      Ansnum += Ans[i];
    }
  }
  cout << Ansnum << endl;
  return 0;
}
