#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int j;
  int M;
  cin >> M;
  vector<int> ans(N);
  long answer;
  answer = 0;
  int i;
  long jousuu;
  vector<int> s(M);
  vector<int> c(M);
  for (i = 0; i < M; i++) {
    cin >> s.at(i);
    cin >> c.at(i);
  }
  ans.at(0) = 1;
  int temp;
  for (i = 0; i < M; i++) {
    for (j = i + 1; j < M; j++) {
      if (c.at(i) < c.at(j)) {
        temp = c.at(i);
        c.at(i) = c.at(j);
        c.at(j) = temp;
        temp = s.at(i);
        s.at(i) = s.at(j);
        s.at(j) = temp;
      }
    }
  }
  for (i = 0; i < M; i++) {
    ans.at(s.at(i) - 1) = c.at(i);
  }
  jousuu = 1;
  for (i = N - 1; i > 0; i--) {
    jousuu = jousuu * 10;
  }
  for (i = 0; i < N; i++) {
    answer = answer + ans.at(i) * jousuu;
    jousuu = jousuu / 10;
  }
  for (i = 0; i < M; i++) {
    for (j = 0; j < M; j++) {
      if (i == j) {
        continue;
      }
      if (s.at(i) == s.at(j)) {
        if (c.at(i) != c.at(j)) {
          answer = (-1);
        }
      }
    }
  }
  for (i = 0; i < M; i++) {
    if (s.at(i) == 1 && c.at(i) == 0) {
      answer = (-1);
    }
  }
  if (N == 1 && s.at(0) == 1 && c.at(0) == 0) {
    answer = 0;
  }
  cout << answer << endl;
}
