#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n + 1);
  for (int i = 0; i < n + 1; i++) v[i] = 100;
  int ans = true;
  for (int i = 0; i < m; i++) {
    int key, vlue;
    cin >> key >> vlue;
    if (v[key] == 100)
      v[key] = vlue;
    else if (v[key] != vlue) {
      ans = false;
    }
  }
  if (m == 0) {
    if (n == 1) cout << "0";
    if (n == 2) cout << "10";
    if (n == 3) cout << "100";
  } else if (ans == false || v[1] == 0)
    cout << "-1";
  else {
    for (int i = 1; i < n + 1; i++) {
      if (v[i] == 100)
        cout << '0';
      else
        cout << v[i];
    }
  }
  return 0;
}
