#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  int ans[3] = {-1, -1, -1};
  cin >> n >> m;
  for (int i = n; i < 3; ++i) ans[i - n] = 0;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (ans[2 - n + s] == c) continue;
    if (ans[2 - n + s] == -1)
      ans[2 - n + s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < 3; ++i)
    if (ans[i] == -1) ans[i] = 0;
  int val = ans[0] * 100 + ans[1] * 10 + ans[2];
  if (val == 0)
    cout << (n == 1 ? val : -1) << endl;
  else {
    int pow10[] = {1, 10, 100, 1000};
    if (pow10[n - 1] <= val && val < pow10[n])
      cout << val << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
