#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = (acos(-1));
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n, m, d = 0, ans = 0;
  cin >> n >> m;
  vector<int> ck(m, 0);
  bool ok = true;
  for (int i = 0; i < (int)(m); ++i) {
    int s, c;
    cin >> s >> c;
    if (ck[s] && ck[s] != c) {
      ans = -1;
      ok = false;
    }
    ck[s] = c;
  }
  if (ok) {
    for (int i = 1; i < (int)(m + 1); ++i) {
      ans += pow(10, m - i) * ck[i];
    }
  }
  if (!ans)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
