#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  long long s[10], c[10];
  long long jikkou;
  long long answer = 0;
  long long error = 0;
  cin >> N;
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  if (N > 1) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 1) {
        if (c[i] == 0) {
          error = 1;
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          error = 1;
        }
      }
    }
  }
  for (int i = 0; i < M; i++) {
    jikkou = 1;
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] == c[j]) {
        jikkou = 0;
      }
    }
    if (jikkou == 1) {
      answer = answer + c[i] * pow(10, N - s[i]);
    }
  }
  if (error == 1) {
    answer = -1;
  }
  cout << answer << endl;
  system("pause");
  return 0;
}
