#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000000001;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};
struct pos {
  long long x, cost;
};
int main() {
  int n, m;
  int c[6], x[4] = {};
  int s[6];
  cin >> n >> m;
  x[1] = -1;
  x[2] = -1;
  x[3] = -1;
  if (n == 1 && m == 0) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    if (x[s[i]] != c[i] && x[s[i]] >= 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (s[i] == 1 && c[i] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    x[s[i]] = c[i];
  }
  int a = 0, t = 1;
  for (int i = n; i > 0; i--) {
    if (x[i] >= 0) a += x[i] * t;
    t *= 10;
  }
  if (x[1] == -1) a += t / 10;
  cout << a << endl;
  return 0;
}
