#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int in() {
  int x;
  cin >> x;
  return x;
}
long long lin() {
  long long x;
  cin >> x;
  return x;
}
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;
}
template <class T>
inline void print(pair<T, T> p) {
  cout << "(" << p.first << "," << p.second << ") ";
}
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
const long long INF = 1e9 + 7;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n, -1);
  bool flag = true;
  for (long long i = 0; i < m; i++) {
    long long p, q;
    cin >> p >> q;
    p--;
    if (s[p] != -1 && s[p] != q) {
      flag = false;
      break;
    } else {
      s[p] = q;
    }
  }
  if (s[0] == 0) {
    flag = false;
  }
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      if (s[i] == -1) {
        cout << 1;
      }
    }
    if (s[i] == -1) {
      cout << 0;
    } else {
      cout << s[i];
    }
  }
  cout << endl;
  return 0;
}
