#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long mod = pow(10, 9) + 7;
const long long INF = pow(2, 31) - 1;
long long gcd(long long x, long long y) {
  long long r;
  while ((r = x % y) != 0) {
    x = y;
    y = r;
  }
  return y;
}
long long lcm(long long x, long long y) {
  x /= gcd(x, y);
  y /= gcd(x, y);
  return (x * y);
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> d(n, -1);
  for (int i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (d[s] == -1)
      d[s] = c;
    else if (d[s] != -1 && d[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (d[i] == -1)
      cout << ((i == 0) ? 1 : 0);
    else
      cout << d[i];
  }
  cout << endl;
  return 0;
}
