#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const long long int inf = 1e15;
const long long int MOD = 1e9 + 7;
const long long int N = 2e5 + 5;
long long int a[10];
string ans;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  long long int flag = 0;
  for (long long int i = 0; i < n; i++) ans += ' ';
  for (long long int i = 0; i < 10; i++) a[i] = -1;
  while (m--) {
    long long int s, c;
    cin >> s >> c;
    if (a[s] != -1 && a[s] != c) flag = 1;
    a[s] = c;
    ans[s - 1] = (char)(c + '0');
  }
  if (n == 1 && ans == " ")
    cout << 0;
  else if (n == 1)
    cout << ans;
  else if (flag == 1)
    cout << -1;
  else {
    if (ans[0] == '0')
      cout << -1;
    else if (ans[0] == ' ')
      ans[0] = '1';
    else {
      for (long long int i = 1; i < n; i++)
        if (ans[i] == ' ') ans[i] = ('0');
      cout << ans << '\n';
    }
  }
  return 0;
}
