#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, s, c, i;
  long long int a[3];
  for (i = 0; i < 3; i++) a[i] = 0;
  cin >> n >> m;
  while (m--) {
    cin >> s >> c;
    s--;
    a[s] = c;
  }
  if (a[0] == 0)
    cout << -1 << "\n";
  else {
    for (i = 0; i < 3; i++) {
      cout << a[i];
    }
  }
  cout << "\n";
}
