#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s[5], c[5];
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; ++i) {
    for (int j = i + 1; j < m; ++j) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int r[3];
  for (int i = 0; i < 3; ++i) r[i] = -1;
  for (int i = 0; i < m; ++i) {
    r[s[i] - 1] = c[i];
  }
  if (n != 1 && r[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (r[0] == -1) r[0] = 1;
  for (int i = 0; i < 3; ++i) {
    if (r[i] == -1) r[i] = 0;
  }
  for (int i = 0; i < n; i++) cout << r[i];
  cout << endl;
  return 0;
}
