#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m + 5], c[m + 5], f[n + 5];
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    f[i] = 0;
  }
  int ans;
  for (int i = 1; i <= m; i++) {
    for (int j = 2; j <= m; j++) {
      if (s[i] == s[j] && c[i] != c[j])
        ans = 0;
      else
        ans = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    f[s[i]] = c[i];
  }
  if (n != 1 && f[1] == 0) ans = 0;
  if (ans == 1) {
    for (int i = 1; i <= n; i++) {
      cout << f[i];
    }
  } else if (ans == 0)
    cout << -1;
  return 0;
}
