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