#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < (int)m; i++) cin >> a[i] >> b[i];
  vector<vector<int>> c(n);
  for (int i = 0; i < (int)m; i++) c[a[i] - 1].push_back(b[i]);
  if (c[0].size() == 0) c[0].push_back(1);
  for (int i = 1; i < (int)n; i++)
    if (c[i].size() == 0) c[i].push_back(0);
  int key = 0;
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)c[i].size(); j++)
      if (c[i][j] != c[i][0]) key = 1;
  if (key == 1 || (n > 1 && c[0][0] == 0))
    cout << -1 << endl;
  else if (n == 3)
    cout << 100 * c[0][0] + 10 * c[1][0] + c[2][0] << endl;
  else if (n == 2)
    cout << 10 * c[0][0] + c[1][0] << endl;
  else
    cout << c[0][0] << endl;
}
