#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  string s(n, '0');
  for (int i = 0; i < m; i++) {
    int x, c;
    cin >> x >> c;
    x--;
    if (s[x] == '0') {
      s[x] = c + 48;
    } else {
      if (s[x] != c + 48) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  bool lz = true;
  string res;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      if (lz) continue;
    } else {
      lz = false;
    }
    res.push_back(s[i]);
  }
  if (res.size() != n) {
    cout << "-1\n";
    return 0;
  }
  cout << res << '\n';
  return 0;
}
