#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool umax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
template <typename T, typename U>
bool compare(T x, U y) {
  return (abs(x - y) <= 1e-9);
}
void solve() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n, 10);
  int m;
  cin >> m;
  while (m--) {
    int pos, dig;
    cin >> pos >> dig;
    if (a[pos - 1] != 10) {
      if (dig != a[pos - 1]) {
        cout << -1;
        return;
      }
    } else {
      a[pos - 1] = dig;
    }
  }
  if (a[0] == 0) {
    if (n >= 2) {
      cout << -1;
      return;
    } else {
      cout << 0;
      return;
    }
  }
  if (a[0] == 10) a[0] = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] == 10) a[i] = 0;
  }
  for (auto &x : a) cout << x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}
