#include <bits/stdc++.h>
using namespace std;
int keta(long long N);
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  long long res = 0;
  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << "-1" << endl;
        return 0;
      } else if (s[i] == s[j]) {
        s[i] = -1;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (s[i] != -1) {
      res += c[i] * pow(10, N - s[i]);
    }
  }
  bool flag = false;
  for (int i = 0; i < M; i++) {
    if (c[i] != 0) flag = true;
  }
  if (flag && res == 0 && N != 1) {
    cout << "-1" << endl;
    return 0;
  }
  if (keta(res) != N) res += pow(10, N - 1);
  cout << res << endl;
}
int keta(long long N) {
  int res = 0;
  for (int i = 0;; i++) {
    N /= 10;
    if (N == 0) return i + 1;
  }
}
