#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n, -1);
  bool is = true;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (s[a - 1] != -1 && s[a - 1] != b) is = false;
    s[a - 1] = b;
  }
  int ans = 0;
  if (n != 1 && s[0] == 0) {
    is = false;
  }
  if (s[0] == -1)
    ans = 1;
  else
    ans = s[0];
  for (int i = 1; i < n; i++) {
    if (s[i] == -1) s[i] = 0;
    ans = 10 * ans + s[i];
  }
  if (is)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
