#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int numd(int x) {
  int cnt = 0;
  while (x) {
    x /= 10;
    cnt++;
  }
  return cnt;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p;
  int ok = 1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    p.emplace_back(s, c);
    for (int j = 0; j < p.size(); j++) {
      if (p[i].first == p[j].first && p[i].second != p[i].second) ok = 0;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return;
  }
  string s(n, ' ');
  for (int i = 0; i < m; i++) {
    s[p[i].first] = '0' + p[i].second;
  }
  for (int i = 0; i < n; i++) {
    if (' ' == s[i]) s[i] = '0';
  }
  if (s[0] != '0') {
    cout << s << endl;
    return;
  }
  cout << -1 << endl;
}
int main() {
  solve();
  return 0;
}
