#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int num = 0;
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int flag;
  int i = 0;
  int j;
  while (i < m) {
    cin >> s[i] >> c[i];
    i++;
  }
  i = 1;
  while (i <= n) {
    flag = 0;
    j = 0;
    num *= 10;
    while (j < m) {
      if (s[j] == i && !(flag)) {
        flag = 1;
        num += c[j];
      } else if (s[j] == i && flag) {
        if (num % 10 != c[j]) flag = -1;
      }
      j++;
    }
    if (i == 1) {
      if (flag && !(num))
        flag = -1;
      else if (!(flag))
        num = 1;
    }
    if (flag < 0) break;
    i++;
  }
  if (flag < 0)
    cout << "-1";
  else
    cout << num;
}
