#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
const int MOD = 1e9 + 7;
const int INF = 2e9;
int n, m;
bool valid;
bool changed[15];
string dig;
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    dig += '0';
  }
  valid = true;
  for (int i = 1, p, q; i <= m; i++) {
    cin >> p >> q;
    if (!changed[p - 1]) {
      dig[p - 1] = q + '0';
      changed[p - 1] = true;
    } else if (changed[p - 1] && dig[p - 1] == q + '0')
      continue;
    else {
      valid = false;
    }
  }
  if (dig[0] == '0' && changed[0]) valid = false;
  if (dig[0] == '0' && !changed[0] && n != 1) dig[0] = '1';
  if (!valid)
    cout << "-1\n";
  else
    cout << dig << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
