#include <bits/stdc++.h>
using namespace std;
int n, m, tmp;
int a[4], s[6], c[6], temp[4] = {0};
bool check() {
  for (int i = 1; i <= n; i++) {
    if (temp[i] == -1) return false;
  }
  return true;
}
bool check2() {
  if (temp[1] == 0 && n > 1)
    return false;
  else
    return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> s[i] >> c[i];
    temp[s[i]] = c[i];
  }
  for (int i = 1; i < m; i++) {
    for (int j = i + 1; j <= m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) temp[s[i]] = -1;
    }
  }
  if (check() && check2()) {
    for (int i = 1; i <= n; ++i) {
      cout << temp[i];
    }
  } else
    cout << -1;
}
