#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N;
  cin >> M;
  int s[M], c[M], result = 0;
  int bit[N];
  bool fixed[N];
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < N; i++) {
    bit[i] = 0;
    fixed[i] = false;
  }
  for (int i = 0; i < M; i++) {
    if (!fixed[s[i] - 1])
      fixed[s[i] - 1] = true;
    else if (fixed[s[i] - 1] && (bit[s[i] - 1] == c[i]))
      ;
    else {
      result = -1;
    }
    bit[s[i] - 1] = c[i];
  }
  for (int i = 0; i < N; i++) {
    if (i == (N - 1))
      result += bit[i];
    else
      result += bit[i] * pow(10, (N - i - 1));
  }
  for (int i = 0; i < N; i++) {
    if (fixed[i]) {
      if (bit[i] == 0) result += pow(10, (N - i + 1));
      break;
    }
  }
  cout << result;
  return 0;
}
