#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
  return a = (a > b) ? b : a;
}
long long const INF = 1LL << 60;
long long const MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  for (long long i = 0; i < (M); i++) cin >> s[i] >> c[i];
  vector<vector<long long>> buf(N);
  for (long long i = 0; i < (M); i++) {
    s[i]--;
    buf[s[i]].push_back(c[i]);
  }
  for (long long i = 0; i < (N); i++) {
    buf[i].erase(unique((buf[i]).begin(), (buf[i]).end()), buf[i].end());
  }
  if (N == 1) {
    if (M == 0)
      cout << 0 << endl;
    else if (((int)(buf[0]).size()) == 1)
      cout << buf[0][0] << endl;
    return 0;
  }
  string str;
  for (long long i = 0; i < (N); i++) {
    if (((int)(buf[i]).size()) >= 2) {
      cout << -1 << endl;
      return 0;
    } else if (((int)(buf[i]).size()) == 1) {
      if (buf[i][0] == 0 && i == 0) {
        cout << -1 << endl;
        return 0;
      }
      str.push_back(char(buf[i][0] + '0'));
    } else if (((int)(buf[i]).size()) == 0) {
      if (i == 0) {
        str.push_back('1');
      } else {
        str.push_back('0');
      }
    }
  }
  cout << str << endl;
  return 0;
}
