#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
const int INF = 1001001001;
const long long int LINF = 1001002003004005006ll;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  int str[n];
  for (int i = 0; i < (int)(n); i++) {
    str[i] = -1;
  }
  int flag = true;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    if (str[s - 1] == -1)
      str[s - 1] = c;
    else {
      if (str[s - 1] != c) flag = false;
    }
  }
  if (!flag || str[0] == 0)
    cout << -1 << endl;
  else {
    if (n == 1 && (str[0] == 0 || str[0] == -1))
      cout << 0 << endl;
    else {
      for (int i = 0; i < (int)(n); i++) {
        if (i == 0 && str[i] == -1)
          cout << 1;
        else if (str[i] == -1)
          cout << 0;
        else
          cout << str[i];
      }
      cout << endl;
    }
  }
  return 0;
}
