#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool dup = false;
  int s[m], c[m], ans[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j]) {
        if (!(c[i] == c[j])) {
          dup = true;
          cout << -1;
          break;
        }
      }
      if (dup == true) break;
    }
  }
  fill(ans + 1, ans + m, 0);
  ans[0] = 1;
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = c[i];
  }
  for (int i = 0; i < m; i++) cout << ans[i];
}
