#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int ans[4] = {-1, -1, -1, -1};
  bool success = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) success = false;
    if (ans[s] != -1 && ans[s] != c) success = false;
    ans[s] = c;
  }
  if (success) {
    for (int i = 1; i <= 3; i++)
      if (ans[i] == -1)
        cout << ((i == 1) ? 1 : 0);
      else
        cout << ans[i];
    cout << "\n";
  } else {
    cout << "-1\n";
  }
  return 0;
}
