#include <bits/stdc++.h>
using namespace std;
int N, M;
int s[10];
int c[10];
int main() {
  cin >> N;
  cin >> M;
  for (int(i) = 0; (i) < (M); (i)++) {
    cin >> s[i];
    cin >> c[i];
    s[i]--;
  }
  int ans[3] = {-1, -1, -1};
  for (int(i) = 0; (i) < (M); (i)++) {
    if (ans[s[i]] != -1) {
      if (ans[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (N != 1 && s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i]] = c[i];
  }
  int ansi = 0;
  for (int(i) = 0; (i) < (3); (i)++) {
    if (ans[i] == -1) {
      if (3 - i == N) {
        ansi += pow(10, N - 1);
      }
    } else {
      ansi += pow(10, N - 1 - i) * ans[i];
    }
  }
  if (ansi == 1) ansi = 0;
  cout << ansi << endl;
  return 0;
}
