#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
long long int mod = 1e9 + 7;
int main() {
  int n, m;
  int num[3];
  for (long long int i = 0; i < 3; i++) num[i] = 1e9 + 7;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s = 3 - s;
    if (num[s] == 1e9 + 7) {
      num[s] = c;
    } else {
      if (num[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 1e9 + 7;
  for (int i = 2; i >= 0; i--) {
    if (num[i] != 1e9 + 7) {
      if (ans == 1e9 + 7) {
        if (num[i] == 0)
          ans = 10;
        else
          ans = num[i];
      } else {
        ans = ans * 10 + num[i];
      }
    } else {
      if (ans != 1e9 + 7) {
        ans *= 10;
      }
    }
  }
  int k = 0;
  int tmp = ans;
  while (tmp > 0) {
    k++;
    tmp /= 10;
  }
  if (m == k) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
