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