#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
  }
  int n, m;
  cin >> n >> m;
  int val[m + 1];
  memset(val, -1, sizeof val);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (val[s] == -1)
      val[s] = c;
    else if (c != val[s])
      ok = false;
  }
  if (!ok) {
    cout << "-1";
    return 0;
  }
  if (n == 1) {
    if (val[1] == -1)
      cout << 0;
    else
      cout << val[1];
    return 0;
  }
  if (val[1] == 0) {
    cout << "-1";
    return 0;
  }
  if (val[1] == -1) val[1] = 1;
  string ans = to_string(val[1]);
  for (int i = 2; i <= n; i++) {
    if (val[i] == -1)
      ans += '0';
    else
      ans += val[i] + '0';
  }
  cout << ans;
  return 0;
}
