#include <bits/stdc++.h>
using namespace std;
int n, m, ans[5];
bool err = false;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) ans[i] = -1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (n != 1 && s == 1 && c == 0) err = true;
    if (ans[s - 1] != -1) err = true;
    ans[s - 1] = c;
  }
  for (int i = 0; i < n; i++) {
    if (n != 1 && i == 0)
      ans[i] = max(ans[i], 1);
    else
      ans[i] = max(ans[i], 0);
  }
  if (err)
    cout << -1 << endl;
  else
    cout << ans[0] << ans[1] << ans[2] << endl;
  return 0;
}
