#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll INF = 1LL << 60;
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;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<bool> b(n);
  bool t = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (n != 1 && s == 0 && c == 0) t = false;
    if (b[s] && a[s] != c) t = false;
    a[s] = c;
    b[s] = true;
  }
  if (t) {
    if (a[0] == 0) a[0] = 1;
    for (auto v : a) cout << v;
  } else
    cout << -1;
  cout << endl;
}
