#include <bits/stdc++.h>
using namespace std;
int poww(int a, int b) {
  int ans = 1;
  if (b == 0) {
    return 1;
  }
  for (int i = 0; i < b; i++) {
    ans *= a;
  }
  return ans;
}
int main() {
  int N, M, answer = 0;
  cin >> N >> M;
  vector<int> s(M, 0);
  vector<int> c(M, 0);
  vector<int> han(N, 0);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i);
    cin >> c.at(i);
  }
  for (int i = 0; i < M; i++) {
    if (s.at(i) == 1 && c.at(i) == 0 && N != 1) {
      cout << -1;
      exit(0);
    }
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        cout << -1;
        exit(0);
      }
    }
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j)) {
        s.at(i) = 0;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (s.at(j) == i + 1) {
        han.at(i) = i + 1;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (s.at(i) == 0) {
      answer += 0;
    } else if (s.at(i) == 1) {
      answer += c.at(i) * (poww(10, N - 1));
    } else if (s.at(i) == 2) {
      answer += c.at(i) * (poww(10, N - 2));
    } else if (s.at(i) == 3) {
      answer += c.at(i) * (poww(10, N - 3));
    }
  }
  for (int i = 0; i < N; i++) {
    if (han.at(i) == i + 1) {
      answer += 0;
    } else {
      if (i + 1 == 1) {
        answer += poww(10, N - 1);
      } else {
        answer += 0;
      }
    }
  }
  cout << answer;
}
