#include <bits/stdc++.h>
using namespace std;
struct Init {
  Init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.precision(20);
    cout << fixed;
  }
} init;
template <typename _Ty>
ostream& operator<<(ostream& ostr, const vector<_Ty>& v) {
  for (int i = 0; i < (int)v.size(); i++) {
    ostr << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return ostr;
}
template <typename _K, typename _V>
ostream& operator<<(ostream& ostr, const map<_K, _V>& v) {
  ostr << "{";
  for (auto iter = v.begin(); iter != v.end(); ++iter) {
    ostr << (*iter).first << ": " << (*iter).second << ", ";
  }
  ostr << "}";
  return ostr;
}
template <typename _K>
ostream& operator<<(ostream& ostr, const set<_K>& v) {
  for (auto iter = v.begin(); iter != v.end(); ++iter) {
    ostr << *iter << (iter != v.end() ? " " : "");
  }
  return ostr;
}
template <typename _K, typename _V>
ostream& operator<<(ostream& ostr, const pair<_K, _V>& v) {
  ostr << "(" << v.first << ", " << v.second << ")";
  return ostr;
}
vector<string> split(const string& s, char delim) {
  vector<string> result;
  stringstream ss(s);
  string item;
  while (getline(ss, item, delim)) {
    if (!item.empty()) {
      result.push_back(item);
    }
  }
  return result;
}
long long powmod(long long n, long long count, long long mod) {
  if (count == 0) return 1;
  if (count % 2 == 0) {
    long long t = powmod(n, count / 2, mod);
    return t * t % mod;
  }
  return n * powmod(n, count - 1, mod) % mod;
}
long long ncr(long long n, long long r, long long mod) {
  long long a;
  if (n < r)
    a = min(n, r - n);
  else
    a = min(n - r, r);
  long long res = 1;
  for (int i = 0; i < a; i++) {
    res = res * (n - i) % mod;
    res = res * powmod(i + 1, mod - 2, mod) % mod;
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  vector<int> ans(n, -1);
  for (int i = 0; i < m; i++) {
    if (ans[s[i] - 1] == -1) {
      ans[s[i] - 1] = c[i];
    } else if (ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      exit(0);
    }
  }
  bool f = false;
  for (int i = 0; i < n; i++) {
    if (ans[i] > 0) f = true;
  }
  if (f) {
    for (int i = 0; i < n; i++) {
      if (ans[i] == -1)
        cout << 0;
      else
        cout << ans[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
