#include <bits/stdc++.h>
using namespace std;
typedef vector<pair<long long int, long long int>> vec_p;
const int MOD = pow(10, 9) + 7;
const int MAX = MOD;
long long int beki(long long int A, long long int B) {
  long long int C = 1;
  for (long long int i = 0; i < B; i++) {
    C *= A;
  }
  return C;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<long long int> s(M);
  vector<long long int> c(M);
  for (long long int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  long long int flag = 0;
  for (long long int i = 0; i < M; i++) {
    for (long long int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j) && !(c.at(i) == c.at(j))) {
        cout << -1 << endl;
        flag = 1;
      }
    }
  }
  for (long long int i = 0; i < M; i++) {
    if (s.at(i) > N && flag == 0) {
      cout << -1 << endl;
      flag == 1;
    }
  }
  if (M == 0 && flag == 0) {
    if (N >= 2) {
      cout << -1 << endl;
    } else {
      cout << 0 << endl;
    }
    flag = 1;
  }
  long long int num1 = 0, num2 = 0, num3 = 0, num_all = 0;
  for (long long int i = 0; i < M; i++) {
    if (s.at(i) == 1) {
      num1 = c.at(i) * beki(10, N - 1);
    } else if (s.at(i) == 2 && N >= 2) {
      num2 = c.at(i) * beki(10, N - 2);
    } else if (s.at(i) == 3 && N >= 3) {
      num3 = c.at(i) * beki(10, N - 3);
    }
  }
  num_all = num1 + num2 + num3;
  long long int flag1 = 0;
  if (num_all == 0 && flag == 0) {
    for (long long int i = 0; i < M; i++) {
      if (N == 3 || N == 2) {
        cout << -1 << endl;
        flag1 = 1;
        break;
      }
    }
    if (flag1 == 0) {
      cout << 0 << endl;
    }
  } else if (flag == 0) {
    if (N == 3 && num1 == 0) {
      cout << -1 << endl;
    } else if (N == 2 && num1 == 0) {
      cout << -1 << endl;
    } else if (N = 1 && num1 == 0) {
      cout << -1 << endl;
    } else {
      cout << num_all << endl;
    }
  }
}
