#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b != 0) return gcd(b, a % b);
  return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
using Graph = vector<vector<int>>;
int main() {
  int n, m;
  cin >> n >> m;
  int a[3] = {-1, -1, -1};
  bool f = true;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] == -1 || a[s - 1] == c)
      a[s - 1] = c;
    else
      f = false;
  }
  if (!a[0]) f = false;
  if (a[0] == -1) a[0] = 1;
  if (f) {
    for (int i = 0; i < (n); i++) {
      cout << max(0, a[i]);
    }
    cout << endl;
  } else
    cout << -1 << endl;
}
