#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
  for (auto& i : a) out << i << " ";
  return out;
}
template <typename T, typename U>
void chkmin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void chkmax(T& a, U b) {
  if (a < b) a = b;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = (int)0; i < (int)m; i++) {
    int s, c;
    cin >> s >> c, --s;
    if (ans[s] != -1 && ans[s] != c) return cout << -1, 0;
    ans[s] = c;
  }
  if (ans[0] == 0) return cout << -1, 0;
  if (n > 1 && ans[0] == -1) ans[0] = 1;
  for (int i = (int)0; i < (int)n; i++) {
    if (ans[i] == -1)
      cout << "0";
    else
      cout << ans[i];
  }
  return 0;
}
