#include <bits/stdc++.h>
using namespace std;
int b10(int x) {
  int num = 1;
  for (int i = 0; i < x; i++) {
    num *= 10;
  }
  return num;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> vec[i][j];
    }
  }
  bool finished = false;
  int answer;
  for (int i = 0; i < M; i++) {
    if (vec[i][0] == 1 && vec[i][1] == 0) {
      answer = -1;
      cout << answer << endl;
      break;
    } else {
      for (int j = 0; j < M; j++) {
        if (vec[i][0] == vec[j][0] && vec[i][1] != vec[j][1]) {
          answer = -1;
          cout << answer << endl;
          finished = false;
          break;
        }
      }
      if (finished) {
        break;
      }
    }
    if (answer != -1) {
      vector<int> sp(N);
      for (int i = 0; i < M; i++) {
        sp[vec[i][0] - 1] = vec[i][1];
      }
      for (int i = 0; i < N; i++) {
        answer += sp[i] * b10(N - 1 - i);
        if (sp[0] == 0) {
          answer += b10(N - 1);
        }
      }
      cout << answer << endl;
    }
  }
}
