#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  int s[6];
  int k[6];
  int num[5];
  memset(num, -1, sizeof(num));
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> k[i];
  }
  int cond = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == s[j] and k[i] != k[j]) {
        cond = 1;
        break;
      }
    }
  }
  if (cond) {
    cout << -1 << '\n';
  } else {
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < m; j++) {
        if (s[j] == i) {
          num[i] = k[j];
        }
      }
    }
    if (num[1] == 0 and n >= 2) {
      cout << -1 << '\n';
    } else {
      for (int i = 1; i <= n; i++) {
        if (num[i] == -1 and i == 1)
          cout << 1;
        else if (num[i] == -1)
          cout << 0;
        else
          cout << num[i];
      }
      cout << '\n';
    }
  }
}
