#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[5], c[5];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if ((s[i] == s[j]) && c[i] != c[j]) {
        cout << "-1" << endl;
        return 0;
      }
      if (s[i] == s[j]) {
        c[i] = 0;
      }
    }
  }
  int res = 0;
  for (int i = 0; i < M; i++) {
    int _keta = 0;
    if (3 - s[i] == 2) {
      _keta = 100;
    }
    if (3 - s[i] == 1) {
      _keta = 10;
    }
    if (3 - s[i] == 0) {
      _keta = 1;
    }
    res += (c[i] * _keta);
  }
  if (to_string(res).length() != N) {
    if (N == 3) {
      res += 100;
    }
    if (N == 2) {
      res += 10;
    }
  }
  if (res == 0) {
    cout << "-1" << endl;
  } else {
    cout << res << endl;
  }
}
