#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (n != 0 && s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (a[s] != c && a[s] != -1) {
      cout << -1 << endl;
      return 0;
    }
    a[s] = c;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] == -1) {
      if (i == 0)
        a[i] = 1;
      else
        a[i] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    ans += a[i] * pow(10, n - 1 - i);
  }
  cout << ans << endl;
  return 0;
}
