#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, M = 4;
int n, m;
int num[N];
int main() {
  cin >> n >> m;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (num[s] && num[s] != c) {
      puts("-1");
      return 0;
    } else
      num[s] = c;
  }
  int t = 0;
  for (int i = 1; i <= n; i++) t = t * 10 + num[i];
  if (n == 1) {
    if (t >= 10)
      puts("-1");
    else
      cout << t << endl;
  } else if (n == 2) {
    if (t < 10 || t >= 100)
      puts("-1");
    else
      cout << t << endl;
  } else {
    if (t < 100 || t >= 1000)
      puts("-1");
    else
      cout << t << endl;
  }
  return 0;
}
