#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Int = long long;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  map<int, int> mp;
  map<int, int>::iterator itr;
  int keta = 0;
  for (int(i) = 0; (i) < (int)(m); (i)++) {
    cin >> s[i] >> c[i];
  }
  for (int(i) = 0; (i) < (int)(m); (i)++) {
    if (mp.count(s[i]) == 0) {
      mp[s[i]] = c[i];
    } else {
      if (mp[s[i]] != c[i]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  if (mp[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    if (mp.count(i + 1) == 0) {
      cout << 0;
    } else {
      cout << mp[i + 1];
    }
  }
}
