#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x / GCD(x, y) * y; }
int main() {
  int n, m;
  cin >> n >> m;
  int s[10], c[10];
  vector<int> ans(n);
  for (int i = (0); i < (n); i++) ans[i] = 0;
  for (int i = (0); i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = (0); i < (m); i++) {
    for (int j = (i + 1); j < (m); j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = (0); i < (m); i++) {
    ans[s[i]] = c[i];
  }
  if (m == 0) ans[0] = 1;
  if (n != 1 && ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = (0); i < (n); i++) cout << ans[i];
  cout << endl;
  return 0;
}
