#include <bits/stdc++.h>
using namespace std;
int n, m;
int num[10], ans[10];
int main() {
  cin >> n >> m;
  if (n > m) {
    cout << "-1";
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    register int tmp;
    cin >> tmp;
    cin >> num[tmp];
    if (!ans[tmp])
      ans[tmp] = num[tmp];
    else if (num[tmp])
      ans[tmp] = min(ans[tmp], num[tmp]);
  }
  bool p0 = false, p1 = false;
  for (int i = 1; i <= n - 1; i++) {
    if (ans[i])
      p1 = true;
    else {
      if (p1) break;
      cout << "-1";
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i];
  return 0;
}
