#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  vector<long long> min(n, 10);
  string ans;
  vector<char> cs(n, '0');
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  if (n == 1) {
    if (m == 0) {
      cout << 0 << endl;
      return 0;
    }
    int min = c[0];
    char ans = '0';
    for (int i = 0; i < (m); i++) {
      if (min != c[i]) {
        cout << -1 << endl;
        return 0;
      }
      ans = min + '0';
    }
  loopend:
    cout << ans << endl;
    return 0;
  }
  bool on = false;
  for (int i = 0; i < (m); i++) {
    if (s[i] == 0 && c[i] > 0) {
      on = true;
    }
  }
  if (!on) {
    cout << "-1" << endl;
    return 0;
  }
  vector<long long> freq(n, -1);
  for (int i = 0; i < (m); i++) {
    for (int j = 0; j < (m); j++) {
      if (freq[s[i]] == -1)
        freq[s[i]] = c[i];
      else if (freq[s[i]] == c[i])
        continue;
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < (m); i++) {
    cs[s[i]] = c[i] + '0';
  }
  for (char tmp : cs) ans.push_back(tmp);
  cout << ans << endl;
  return 0;
}
