#include <bits/stdc++.h>
using namespace std;
int number(int n, int m, int s[], int c[]) {
  if (m == 0) {
    if (n == 3)
      return 100;
    else if (n == 2)
      return 10;
    else
      return 0;
  }
  if (n > 1 && s[0] == 1 && c[0] == 0) return -1;
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j]) {
        if (c[i] == c[j])
          continue;
        else
          return -1;
      }
    }
  }
  int h[4] = {}, sum = 0;
  for (int i = 0; i < m; i++) h[s[i]] = c[i];
  if (n == 2 && h[1] == 0 || n == 3 && h[1] == 0 ||
      n == 3 && h[1] == 0 && n == 3 && h[2] == 0)
    return -1;
  for (int i = n, j = 0; i >= 1; i--, j++) {
    sum += h[i] * pow(10, j);
  }
  return sum;
}
int main() {
  int n, m, s[4], c[10], res;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  res = number(n, m, s, c);
  cout << res;
  return 0;
}
