#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int func(vector<int> &v) {
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    cnt = cnt + (v[i] * pow(10, v.size() - i - 1));
  }
  return cnt;
}
int main(void) {
  fast();
  int a, b;
  int m, n;
  cin >> n >> m;
  if (m == 0) {
    for (int i = 0; i < n; i++) {
      cout << 0;
    }
    cout << "\n";
    return 0;
  }
  vector<int> v(n, -1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (v[a - 1] == -1 || v[a - 1] == b) {
      v[a - 1] = b;
    } else {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (n == 1 && v[0] == -1) {
    cout << 0 << "\n";
    return 0;
  } else if (n == 1) {
    cout << v[0] << "\n";
    return 0;
  }
  if (v[0] == 0) {
    cout << -1 << "\n";
    return 0;
  } else {
    if (v[0] == -1) {
      v[0] = 1;
    }
    for (int i = 0; i < n; i++) {
      if (v[i] == -1) {
        v[i] = 0;
      }
    }
    int var = func(v);
    cout << var << "\n";
    return 0;
  }
}
