#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
int main() {
  int n, m;
  cin >> n >> m;
  vin s(m), c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  bool ok = true;
  int ans = 0;
  for (int i = 0; i < (m); i++) {
    if (s[i] == 1 && c[i] == 0) ok = false;
  }
  map<int, int> mp;
  for (int i = 0; i < (m); i++) {
    if (mp.count(s[i])) {
      if (mp[s[i]] != c[i]) {
        ok = false;
      }
    } else {
      mp[s[i]] = c[i];
      ans += c[i] * pow(10, n - s[i]);
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
