#include <bits/stdc++.h>
using namespace std;
const long long INFi = 2147483647;
const long long INFl = 9223372036854775807LL;
template <typename T>
T abs(T a, T b) {
  return max(a, b) - min(a, b);
}
template <typename T>
T lcm(T a, T b) {
  return (a * b) / gcd(a, b);
}
long long gcd(long long a, long long b) {
  long long c = a % b;
  while (true) {
    if (c == 0) break;
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  long long s, c;
  bool num[10] = {};
  long long date[10] = {};
  bool f = true;
  cin >> n >> m;
  for (long long i = 0; i < 9; i++) {
    date[i] = -1;
  }
  for (long long i = 0; i < m; i++) {
    cin >> s >> c;
    if (num[s] == 1) {
      if (date[s] != c) f = false;
    } else {
      num[s] = 1;
      date[s] = c;
    }
  }
  if (f == true && date[1] != 0) {
    if (num[1] == 1)
      cout << date[1];
    else
      cout << "1";
    for (long long i = 2; i <= n; i++) {
      if (num[i] == 1)
        cout << date[i];
      else
        cout << "0";
    }
  } else {
    if (date[1] == 0 && n == 1)
      cout << "0";
    else
      cout << "-1";
  }
  cout << "\n";
}
