#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T>
void printv(const vector<T>& s) {
  for (int i = 0; i < (int)(s.size()); ++i) {
    cout << s[i];
    if (i == (int)(s.size()) - 1)
      cout << endl;
    else
      cout << " ";
  }
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  vector<int> v(n, -1);
  bool ok = true;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (n == 1) {
      if (v[s] != -1 && v[s] != c) {
        ok = false;
      } else {
        v[s] = c;
      }
      continue;
    }
    if ((s == 0 && c == 0) || (v[s] != -1 && v[s] != c)) {
      ok = false;
    } else {
      v[s] = c;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (v[i] == -1) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      cout << v[i];
    }
  }
  cout << endl;
}
